Joshua, Daniel
Thanks very much for your quick response.
I tried Joshua¹s suggestion but it didn¹t work.
I don¹t understand what you suggest Daniel. What should fileFromU2 be?
I may be wrong by using the Client method in the first place. ?? The purpose of my script is to use an API which is set up as a SOAP service.
Why would I need to download the WSDL file and then pass it to the transport hack when I can¹t even get the WSDL and the purpose of client = Client (WSDL) is to connect to the WSDL itself?
Cheers
Janet
On 7/10/10 09:33, "Daniel Rodriguez" danjrod@gmail.com wrote:
Hi,
I think the problem is in the connect itself.
The standard transport included in suds assumes that only the SOAP calls may need authentication or other things. Downloading the WSDL is attempted with a plain HTTP GET (Not even POST is allowed)
I guess that the transport covers at least 95% of standard situations, but it didn't for example cover mine, where I wanted to embed the WSDSL as a string in my code. Of course only with my own transport I could give suds a "file" object with the content of the string.
It is my feeling that a better transport could be written (we have seen some examples shared in the mailing list) although some use cases may require re-thinking how a Client is initialized.
In the case pertaining to Janet, I guess she may download the WSDL file as you suggest, pass it to the transport hack below. She may then use this transport during client initialization. Obviously this is only good for 1 WSDL file. (The transport below can also load WSDL content directly from a string)
class TransportHack(Transport): def __init__(self, wsdlFile=None, **kwargs): Transport.__init__(self, **kwargs) self.wsdlcontent = wsdlFile
def open(self, request): if self.wsdlFile is not None: return self.wsdlFile
log.debug('opening: (%s)', request.url) fp = None location = request.url.lstrip() if location.startswith('<?'): log.debug('returning url (%s) as StringIO file') fp = StringIO(location) else: parsed = urlparse(request.url) if parsed.scheme == 'file': log.debug('opening file (%s) with open', parsed.path) try: fp = open(parsed.path) except Exception, e: raise TransportError(str(e), 503, StringIO('')) else: log.debug('opening scheme (%s) over the network', parsed.scheme) try: url = request.url log.debug('opening (%s)', url) u2request = u2.Request(url) self.proxy = self.options.proxy return self.u2open(u2request) except u2.HTTPError, e: raise TransportError(str(e), e.code, e.fp) return fp
Then do something like
myClient = suds.client.Client(wsdl, transport=HackTransport(fileFromU2), etc)
Best regards
Daniel
On Wed, Oct 6, 2010 at 21:22, Joshua J. Kugler joshua@eeinternet.com wrote:
On Wednesday 06 October 2010, Janet Valbuena elucidated thus:
Hi
I'm new to suds (have just downloaded it after getting frustrated with SOAPpy).
I'm trying to connect to a WSDL which requires basic HTTP authentication. I have been able to connect to it correctly using PHP but I need to use Python.
This is my code:
#!/usr/bin/python
Username = "user" Password = "pass123" from suds.transport.http import HttpAuthenticated t = HttpAuthenticated(username=Username, password=Password)
# WSDL is only available in internal network WSDL = "http://localhost:18080/external/services/DomService?wsdl" from suds.client import Client client = Client(WSDL, transport=t)
And this is the error it returns:
Traceback (most recent call last): File "./wsdltest.py", line 25, in <module> client = Client(wsdl, transport=t) File "build/bdist.linux-i686/egg/suds/client.py", line 112, in __init__ File "build/bdist.linux-i686/egg/suds/reader.py", line 152, in open File "build/bdist.linux-i686/egg/suds/wsdl.py", line 136, in __init__ File "build/bdist.linux-i686/egg/suds/reader.py", line 79, in open File "build/bdist.linux-i686/egg/suds/reader.py", line 101, in download File "build/bdist.linux-i686/egg/suds/sax/parser.py", line 136, in parse File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 125, in parse self.close() File "/usr/lib/python2.5/xml/sax/expatreader.py", line 217, in close self.feed("", isFinal = 1) File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: <unknown>:1:0: no element found
I would try to download the file with a quick urllib2 script and see what you get. The error is not in the connect (that would raise its own exception) but in trying to parse what *is* being downloaded.
Something like:
import urllib2 auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm='name_of_your_realm', uri='your_url_without_the_file_name', user=User, passwd=Password) opener = urllib2.build_opener(auth_handler) urllib2.install_opener(opener)
print urllib2.open(WSDL).read()
j
-- Joshua Kugler Part-Time System Admin/Programmer http://www.eeinternet.com - Fairbanks, AK PGP Key: http://pgp.mit.edu/ ID 0x73B13B6A _______________________________________________ suds mailing list suds@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/suds
Hi Janet,
The code provided by Joshua lets you download the WSDL to a "file" object. That's why the last statement of his example is:
print urllib2.open(WSDL).read()
whis is basically first opening a file (open), then reading the content to a string (read) and printing it to standard output. If you simply do:
fileFromU2 = urllib2.open(WSDL)
you get direct acess to the file object and can pass it to the hacked transport I provided before.
Best regards
Daniel
On Thu, Oct 7, 2010 at 13:03, Janet Valbuena janet.valbuena@tpp.com.auwrote:
Joshua, Daniel
Thanks very much for your quick response.
I tried Joshua’s suggestion but it didn’t work.
I don’t understand what you suggest Daniel. What should fileFromU2 be?
I may be wrong by using the Client method in the first place. ?? The purpose of my script is to use an API which is set up as a SOAP service.
Why would I need to download the WSDL file and then pass it to the transport hack when I can’t even get the WSDL and the purpose of *client = Client (WSDL)* is to connect to the WSDL itself?
Cheers
Janet
On 7/10/10 09:33, "Daniel Rodriguez" danjrod@gmail.com wrote:
Hi,
I think the problem is in the connect itself.
The standard transport included in suds assumes that only the SOAP calls may need authentication or other things. Downloading the WSDL is attempted with a plain HTTP GET (Not even POST is allowed)
I guess that the transport covers at least 95% of standard situations, but it didn't for example cover mine, where I wanted to embed the WSDSL as a string in my code. Of course only with my own transport I could give suds a "file" object with the content of the string.
It is my feeling that a better transport could be written (we have seen some examples shared in the mailing list) although some use cases may require re-thinking how a Client is initialized.
In the case pertaining to Janet, I guess she may download the WSDL file as you suggest, pass it to the transport hack below. She may then use this transport during client initialization. Obviously this is only good for 1 WSDL file. (The transport below can also load WSDL content directly from a string)
class TransportHack(Transport): def __init__(self, wsdlFile=None, **kwargs): Transport.__init__(self, **kwargs) self.wsdlcontent = wsdlFile def open(self, request): if self.wsdlFile is not None: return self.wsdlFile log.debug('opening: (%s)', request.url) fp = None location = request.url.lstrip() if location.startswith('<?'): log.debug('returning url (%s) as StringIO file') fp = StringIO(location) else: parsed = urlparse(request.url) if parsed.scheme == 'file': log.debug('opening file (%s) with open', parsed.path) try: fp = open(parsed.path) except Exception, e: raise TransportError(str(e), 503, StringIO('')) else: log.debug('opening scheme (%s) over the network',
parsed.scheme) try: url = request.url log.debug('opening (%s)', url) u2request = u2.Request(url) self.proxy = self.options.proxy return self.u2open(u2request) except u2.HTTPError, e: raise TransportError(str(e), e.code, e.fp) return fp
Then do something like
myClient = suds.client.Client(wsdl, transport=HackTransport(fileFromU2), etc)
Best regards
Daniel
On Wed, Oct 6, 2010 at 21:22, Joshua J. Kugler joshua@eeinternet.com wrote:
On Wednesday 06 October 2010, Janet Valbuena elucidated thus:
Hi
I'm new to suds (have just downloaded it after getting frustrated with SOAPpy).
I'm trying to connect to a WSDL which requires basic HTTP authentication. I have been able to connect to it correctly using PHP but I need to use Python.
This is my code:
#!/usr/bin/python
Username = "user" Password = "pass123" from suds.transport.http import HttpAuthenticated t = HttpAuthenticated(username=Username, password=Password)
# WSDL is only available in internal network WSDL = "http://localhost:18080/external/services/DomService?wsdl" from suds.client import Client client = Client(WSDL, transport=t)
And this is the error it returns:
Traceback (most recent call last): File "./wsdltest.py", line 25, in <module> client = Client(wsdl, transport=t) File "build/bdist.linux-i686/egg/suds/client.py", line 112, in __init__ File "build/bdist.linux-i686/egg/suds/reader.py", line 152, in open File "build/bdist.linux-i686/egg/suds/wsdl.py", line 136, in __init__ File "build/bdist.linux-i686/egg/suds/reader.py", line 79, in open File "build/bdist.linux-i686/egg/suds/reader.py", line 101, in download File "build/bdist.linux-i686/egg/suds/sax/parser.py", line 136, in parse File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 125, in parse self.close() File "/usr/lib/python2.5/xml/sax/expatreader.py", line 217, in close self.feed("", isFinal = 1) File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: <unknown>:1:0: no element found
I would try to download the file with a quick urllib2 script and see what you get. The error is not in the connect (that would raise its own exception) but in trying to parse what *is* being downloaded.
Something like:
import urllib2 auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm='name_of_your_realm', uri='your_url_without_the_file_name', user=User, passwd=Password) opener = urllib2.build_opener(auth_handler) urllib2.install_opener(opener)
print urllib2.open(WSDL).read()
j
-- Joshua Kugler Part-Time System Admin/Programmer http://www.eeinternet.com - Fairbanks, AK PGP Key: http://pgp.mit.edu/ ID 0x73B13B6A _______________________________________________ suds mailing list suds@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/suds