|
SUDS version 0.4 pn x86_64 Python 2.7
I'm having a bear of a time getting HTTP Basic Authentication to work for a SOAP request via suds. Also using an HTTP proxy server. In WireShark I just see a request - GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 Accept-Encoding: identity Host: ....... Connection: close User-Agent: Python-urllib/2.7 This doesn't contain any authentication credentials so the response is HTTP/401, and the client doesn't retry with credentials. The response does come from the remote as I can see there is a WWW-Authenticate header and it is from an Apache Tomcat server - so it makes it through the proxy server. Code ================ url = 'http://....../services/services/JobService-0.0.1?wsdl' proxy = urllib2.ProxyHandler({'http': '<a href="http://.....:3128'">http://.....:3128'}) transport = suds.transport.http.HttpAuthenticated() transport.urlopener = urllib2.build_opener(proxy) client = suds.client.Client(url, transport=transport, username='******', password='********') .... I've tried the above as well as the method described at <http://blogs.oucs.ox.ac.uk/inapickle/2011/05/14/exchange-web-services-suds-and-python/> It has the same problem. Back Trace ================ Traceback (most recent call last): File "etrace.py", line 30, in <module> client = suds.client.Client(url, transport=transport, username='*******', password='*****') File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ self.wsdl = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open d = self.fn(url, self.options) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ d = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open d = self.download(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download fp = self.options.transport.open(Request(url)) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open return HttpTransport.open(self, request) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open raise TransportError(str(e), e.code, e.fp) suds.transport.TransportError: HTTP Error 401: Unauthorized -- System & Network Administrator [ LPI & NCLA ] <http://www.whitemiceconsulting.com> OpenGroupware Developer <http://www.opengroupware.us> Adam Tauno Williams -- http://mail.python.org/mailman/listinfo/python-list |
|
El 08/03/12 16:44, Adam Tauno Williams escribió:
> SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > Accept-Encoding: identity > Host: ....... > Connection: close > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > HTTP/401, and the client doesn't retry with credentials. The response > does come from the remote as I can see there is a WWW-Authenticate > header and it is from an Apache Tomcat server - so it makes it through > the proxy server. > > Code > ================ > url = 'http://....../services/services/JobService-0.0.1?wsdl' > proxy = urllib2.ProxyHandler({'http': '<a href="http://.....:3128'">http://.....:3128'}) > transport = suds.transport.http.HttpAuthenticated() > transport.urlopener = urllib2.build_opener(proxy) > client = suds.client.Client(url, transport=transport, > username='******', password='********') > .... > > I've tried the above as well as the method described at > <http://blogs.oucs.ox.ac.uk/inapickle/2011/05/14/exchange-web-services-suds-and-python/> It has the same problem. > > > Back Trace > ================ > Traceback (most recent call last): > File "etrace.py", line 30, in<module> > client = suds.client.Client(url, transport=transport, > username='*******', password='*****') > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ > self.wsdl = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ > d = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open > d = self.download(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download > fp = self.options.transport.open(Request(url)) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open > return HttpTransport.open(self, request) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > raise TransportError(str(e), e.code, e.fp) > suds.transport.TransportError: HTTP Error 401: Unauthorized > (telnet/curl/wget,...) adding all needed headers/data manually so I'm totally sure the request is OK, if everything goes Ok you know your python code need to be reviewed but when you are under proxies you can find a lot of not python related issues (bad gateways, using proxy when it shouldn't or vice-versa, requests changed by proxy,....). wireshark can be very useful but in situations like this I usually prefer tcpflow output, I think the request/response flow showed is really useful, but that's a personal preference. HTH, bye -- http://mail.python.org/mailman/listinfo/python-list |
|
On Fri, 2012-03-09 at 00:03 +0100, Rafael Durán Castañeda wrote:
> El 08/03/12 16:44, Adam Tauno Williams escribió: > > SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > > Accept-Encoding: identity > > Host: ....... > > Connection: close > > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > > HTTP/401, and the client doesn't retry with credentials. The response > > does come from the remote as I can see there is a WWW-Authenticate > > header and it is from an Apache Tomcat server - so it makes it through > > the proxy server. > > Code > > ================ > > url = 'http://....../services/services/JobService-0.0.1?wsdl' > > proxy = urllib2.ProxyHandler({'http': '<a href="http://.....:3128'">http://.....:3128'}) > > transport = suds.transport.http.HttpAuthenticated() > > transport.urlopener = urllib2.build_opener(proxy) > > client = suds.client.Client(url, transport=transport, > > username='******', password='********') > > .... > > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > > raise TransportError(str(e), e.code, e.fp) > > suds.transport.TransportError: HTTP Error 401: Unauthorized > When I've got issues like yours, I usually try using a console client > (telnet/curl/wget,...) adding all needed headers/data manually so I'm > totally sure the request is OK, if everything goes Ok you know your > python code need to be reviewed but when you are under proxies you can > find a lot of not python related issues (bad gateways, using proxy when > it shouldn't or vice-versa, requests changed by proxy,....). Nope, proxy works perfectly [for hundreds of clients]. The problem turned out to be that SUDS uses the specified transport for SOAP requests/operations. When requesting the WSDL in order to built the client interface it doesn't use the transport. So either download the service description to a local file and use that or just use urllib2 to retrieve the WSDL to a buffer (outside of SUDS). Once the client is created the requests work with authentication and via the proxy with no issues. > wireshark can be very useful but in situations like this I usually > prefer tcpflow output, I think the request/response flow showed is > really useful, but that's a personal preference. Wireshark does the same thing; you just select a packet in the stream and then select "follow conversation". -- System & Network Administrator [ LPI & NCLA ] <http://www.whitemiceconsulting.com> OpenGroupware Developer <http://www.opengroupware.us> Adam Tauno Williams -- http://mail.python.org/mailman/listinfo/python-list |
| Powered by Nabble | Edit this page |
