Django 与肥皂水的奇怪行为
Django strange behavior with suds
我正在使用 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
由于没有使用正确的 transport
class,我在生产之前遇到过同样的问题 运行。在我的例子中,对于生产 https 是强制的,而开发是严格的 http。
从 this question -
Suds 提供了两个 HttpAuthenticated classes,一个在 suds.transport.http 模块中,第二个在 suds.transport.https 模块中。看起来你是从 suds.transport.http 实例化的,但是由于你的 URL 是 https://,你可能想尝试 suds.transport.https.HttpAuthenticated.
我正在使用 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
由于没有使用正确的 transport
class,我在生产之前遇到过同样的问题 运行。在我的例子中,对于生产 https 是强制的,而开发是严格的 http。
从 this question -
Suds 提供了两个 HttpAuthenticated classes,一个在 suds.transport.http 模块中,第二个在 suds.transport.https 模块中。看起来你是从 suds.transport.http 实例化的,但是由于你的 URL 是 https://,你可能想尝试 suds.transport.https.HttpAuthenticated.