RosesDurden / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

Cannot access WSDL that requires basic authentication #113

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Attempt to access a WSDL that requires basic authentication

What is the expected output?
I would like to be able to provide credentials to web service provider that are 
used during the fetch process.

What do you see instead?
xml.parsers.expat.ExpatError: mismatched tag: line 1, column 919
Because this code in client.py:
  # Open uri and read xml:
  xml = fetch(url, self.http, cache, force_download, self.wsdl_basedir)
Is assuming it's going to get a WSDL back, but if you get a 401 error, the you 
get the mismatched tag error.  Also, as you can see, the only thing passed into 
the fetch method that could affect authentication is self.http.

What version of the product are you using? On what operating system?
1.10 on OS X 10.7.5

Please provide any additional information below.
I am able to get this to work by altering client.py:

Starting on line 64 - I added a username and password options:
    def __init__(self, location=None, action=None, namespace=None,
                 cert=None, exceptions=True, proxy=None, ns=False,
                 soap_ns=None, wsdl=None, wsdl_basedir='', cache=False, cacert=None,
                 sessions=False, soap_server=None, timeout=TIMEOUT,
                 http_headers={}, username=None, password=None
                 ):

Then on line 110, I added a call to add_credentials on the self.http object 
which is passed into the fetch method:
        if username and password:
            self.http.add_credentials(username, password)

This solves the problem I am having.

Original issue reported on code.google.com by andy.kin...@gmail.com on 1 Sep 2013 at 3:28

GoogleCodeExporter commented 8 years ago
I had to make this change as well. You can pass in headers to authenticate when 
you call the wsdl methods with:

encoded = base64.b64encode("%s:%s" % (username, password))
client = SoapClient(wsdl=u, trace=True, 
                    http_headers={'Authorization': 'Basic %s' % encoded})

....BUT if your wsdl definition is behind http authentication as well, those 
headers are not passed into the self.http method, which makes the above fix a 
requirement for wsdl's behind http auth. 

Until this change is in, I have to keep a clone of the repo? No pull requests 
on google code either? 

Anyone know when this three liner can be added? 

And the if statement should probably be: 

if hasattr(self.http, 'add_credentials') and username and password:

Original comment by curran...@gmail.com on 20 Dec 2013 at 4:58

GoogleCodeExporter commented 8 years ago
Merged, thanks!

Please run the tests and report any new issue!

Thanks again for your contribution

Original comment by reingart@gmail.com on 20 Dec 2013 at 5:43

GoogleCodeExporter commented 8 years ago
Issue 126 has been merged into this issue.

Original comment by reingart@gmail.com on 20 Dec 2013 at 7:52

GoogleCodeExporter commented 8 years ago
Hello,
There seem to be an issue with simple auth between python 2.7.3 (debian stable) 
and 2.6.8. pysimplesoap version 1.13.
The adding of username and password works in 2.6.8 but does not work in 2.7.3

{{{
Python 2.6.8 (unknown, Jan 26 2013, 14:35:25) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysimplesoap.client import SoapClient, SoapFault, SimpleXMLElement
>>> url='https://xxxxx?WSDL'
>>> client = SoapClient(wsdl=url, username="myuser",password="mysecretpass")
>>> 
}}}

{{{
(env2)lucas@delle6510:~/tmp/12/pysimplesoap$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysimplesoap.client import SoapClient, SoapFault, SimpleXMLElement
>>> url='https://xxxx?WSDL'
>>> client = SoapClient(wsdl=url, username="sss",password="rrrr")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pysimplesoap/client.py", line 164, in __init__
    self.services = wsdl and self.wsdl_parse(wsdl, cache=cache)
  File "pysimplesoap/client.py", line 520, in wsdl_parse
    xml = fetch(url, self.http, cache, force_download, self.wsdl_basedir)
  File "pysimplesoap/helpers.py", line 77, in fetch
    response, xml = http.request(url, 'GET', None, {})
  File "pysimplesoap/transport.py", line 135, in request
    f = self.request_opener(req, timeout=self._timeout)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 407, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 445, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized
}}}

Original comment by szybal...@gmail.com on 15 May 2014 at 10:27

GoogleCodeExporter commented 8 years ago
Hello,
Looks like httplib2 is required to make pysimplesoap basic http authentication 
working. My python2.6 had it while 2.7 didn't. Installing httplib2 fixes the 
issue.

pip install httplib2
or
aptitude install python-httplib2

Looks like without it this does not work. Not sure if httplib2 should be 
require as part of this package dependency.

Also as a reference this ticket code changes is checked into 1.12 version not 
currently available in easy_install or pip as of 5/16/2014. You have to get the 
source which is at 1.13

Original comment by szybal...@gmail.com on 16 May 2014 at 4:42

GoogleCodeExporter commented 8 years ago
Hi,

I just now did a pip install pysimplesoap and py install httplib2 on Python 3.4.
I get this:
Traceback (most recent call last):
  File "pythonsoap.py", line 6, in <module>
    client = SoapClient(wsdl="wsdlserver/path?wsdl",username=username,password=password)
TypeError: __init__() got an unexpected keyword argument 'username'

Is by any chance this fix not included in version 10?

Original comment by johan...@gmail.com on 14 Jan 2015 at 9:22