我正在使用suds来使用WebService,而且我遇到了一个奇怪的错误。
当我第一次调用WebService时,它失败了。当我刷新页面时它也会失败。当我第二次刷新页面时,它可以正常工作。
你们有没有想过为什么只有当我刷新两次页面时它才有效?
urls.py:
url(r'^test/$', views.formulaire),
url(r'^test/(?P<rechercher>.*\d+)/$', views.formulaire), #optional = .*
views.py:
url = 'https://myWebService.com/Action.asmx?WSDL'
username='username'
password='password'
client = Client(url=url, username=username, password=password)
前两次收到以下消息:
TransportError at /blog/test/
HTTP Error 401: Unauthorized
Traceback:
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\transport\http.py" in open
67. return self.u2open(u2request)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\transport\http.py" in u2open
132. return url.open(u2request, timeout=tm)
File "C:\Python34\lib\urllib\request.py" in open
470. response = meth(req, response)
File "C:\Python34\lib\urllib\request.py" in http_response
580. 'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py" in error
502. result = self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py" in _call_chain
442. result = func(*args)
File "C:\Python34\lib\urllib\request.py" in http_error_401
901. url, req, headers)
File "C:\Python34\lib\urllib\request.py" in http_error_auth_reqed
879. return self.retry_http_basic_auth(host, req, realm)
File "C:\Python34\lib\urllib\request.py" in retry_http_basic_auth
889. return self.parent.open(req, timeout=req.timeout)
File "C:\Python34\lib\urllib\request.py" in open
470. response = meth(req, response)
File "C:\Python34\lib\urllib\request.py" in http_response
580. 'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py" in error
508. return self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py" in _call_chain
442. result = func(*args)
File "C:\Python34\lib\urllib\request.py" in http_error_default
588. raise HTTPError(req.full_url, code, msg, hdrs, fp)
During handling of the above exception (HTTP Error 401: Unauthorized), another exception occurred:
File "C:\Python34\lib\site-packages\django-1.9.1-py3.4.egg\django\core\handlers\base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "C:\Python34\lib\site-packages\django-1.9.1-py3.4.egg\django\core\handlers\base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\wamp\www\crepes_bretonnes\blog\views.py" in formulaire
91. client = Client(url=url, username=username, password=password)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\client.py" in __init__
115. self.wsdl = reader.open(url)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\reader.py" in open
150. d = self.fn(url, self.options)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\wsdl.py" in __init__
136. d = reader.open(url)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\reader.py" in open
74. d = self.download(url)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\reader.py" in download
92. fp = self.options.transport.open(Request(url))
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\transport\https.py" in open
62. return HttpTransport.open(self, request)
File "C:\Python34\lib\site-packages\suds_jurko-0.6-py3.4.egg\suds\transport\http.py" in open
69. raise TransportError(str(e), e.code, e.fp)
Exception Type: TransportError at /blog/test/
Exception Value: HTTP Error 401: Unauthorized
答案 0 :(得分:2)
由于没有使用正确的transport
类,我在生产之前遇到了同样的问题。就我而言,生产https是强制性的,而开发是严格的http。
来自this question -
Suds提供了两个HttpAuthenticated类,一个在suds.transport.http模块中,另一个在suds.transport.https模块中。它似乎是你从suds.transport.http实例化的,但是由于你的URL是https://,你可能想尝试suds.transport.https.HttpAuthenticated。