0

I'm using suds to consume a WebService and i'm facing a strange error.

When I first make a call to the WebService, it fails. When I refresh the page once it fails too. When I refresh the page a second time, it works.

Do you guys have any idea why it only works when I refresh the page twice?

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)

The first two time I get the following message :

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
Creed
  • 163
  • 1
  • 1
  • 13

1 Answers1

2

I have run into the same issue before in production due to not using the right transport class. In my case, for production https is forced while development is strictly http.

From this question -

Suds provides two HttpAuthenticated classes, one in the suds.transport.http module and the second in the suds.transport.https module. It appears your instantiating from suds.transport.http, however since your URL is https://, you may want to try suds.transport.https.HttpAuthenticated.

Community
  • 1
  • 1
Ian Price
  • 7,416
  • 2
  • 23
  • 34