SOAP with suds引发TransportError,代码为500

时间:2016-10-04 06:13:58

标签: python soap suds

我尝试使用suds包连接到Web服务,但是我得到了TransportError,我做错了什么?

from suds.client import Client
wsdl_url = 'https://sep.shaparak.ir/payments/referencepayment.asmx?WSDL'
client = Client(wsdl_url)

这是我得到的错误:

    Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\suds\transport\http.py", line 67, in open
    return self.u2open(u2request)
  File "C:\Python34\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\Python34\lib\urllib\request.py", line 469, in open
    response = meth(req, response)
  File "C:\Python34\lib\urllib\request.py", line 579, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python34\lib\urllib\request.py", line 507, in error
    return self._call_chain(*args)
  File "C:\Python34\lib\urllib\request.py", line 441, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 587, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\suds\client.py", line 115, in __init__
    self.wsdl = reader.open(url)
  File "C:\Python34\lib\site-packages\suds\reader.py", line 150, in open
    d = self.fn(url, self.options)
  File "C:\Python34\lib\site-packages\suds\wsdl.py", line 136, in __init__
    d = reader.open(url)
  File "C:\Python34\lib\site-packages\suds\reader.py", line 74, in open
    d = self.download(url)
  File "C:\Python34\lib\site-packages\suds\reader.py", line 92, in download
    fp = self.options.transport.open(Request(url))
  File "C:\Python34\lib\site-packages\suds\transport\https.py", line 62, in open
    return HttpTransport.open(self, request)
  File "C:\Python34\lib\site-packages\suds\transport\http.py", line 69, in open
    raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 500: Internal Server Error

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并通过使用zeep库进行汤协议解决了该问题。 似乎suds库的开发已停止。因此,您应该切换到该替代方法。

安装zeep之后,您可以将代码替换为下面的代码,然后完成所有操作。

from zeep import Client
wsdl_url = 'https://sep.shaparak.ir/payments/referencepayment.asmx?WSDL'
client = Client(wsdl_url)