You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Django中用Zeep对接支付网关遇AttributeError错误求助

Django对接Zeep支付网关报错:AttributeError at /callback/ module 'zeep.client' has no attribute 'service'

错误信息

AttributeError at /callback/ module 'zeep.client' has no attribute 'service'

相关代码(shop应用views.py回调函数)

# Callback function
def callback(request):
    if request.GET.get('Status') == 'NOK':
        authority = request.GET.get('authority')
        invoice = get_object_or_404(models.Invoice, authority=authority)
        amount = 0
        order = invoice.order
        order_items = models.OrderItem.objects.filter(order=order)
        for item in order_items:
            amount += item.product_cost
        result = client.service.PaymentVerification(MERCHANT, authority, amount)
        if result.Status == 100:
            return render(request, 'callback.html', {'invoice': invoice})
        else:
            return HttpResponse('error ' + str(result.Status))
    else:
        return HttpResponse('error ')

解决方法

  • 正确初始化Zeep客户端:service属性属于实例化后的Client对象,而非zeep.client模块。需先创建Client实例:

    # 在views.py顶部添加
    from zeep import Client
    
    # 替换为支付网关提供的WSDL地址
    PAYMENT_WSDL = "https://your-payment-provider.wsdl"
    client = Client(wsdl=PAYMENT_WSDL)
    

    确保后续代码中使用的client是这个实例,而非导入的zeep.client模块。

  • 检查变量作用域与命名冲突:确认callback函数中引用的client是你初始化的实例,避免因变量名重复(比如误将zeep.client模块导入为client)导致的错误。

  • 验证Zeep版本:通过pip show zeep查看当前版本,若版本过旧或过新,参考对应版本的官方文档调整客户端初始化方式,确保API调用符合版本要求。

内容的提问来源于stack exchange,提问作者Hamed 3dart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 00:01:03