Hi Matt et all
I've actually solved the problem last week.
Unfortunately I have to say the documentation didn't help. I tried all the
options in
, but none
of them worked.
Why? I don't have any idea. I'm using suds 0.4 and Python 2.4.4.
After several attempts guessing how to solve the problem this was the
solution:
import base64
Username = “user”
Password = “abc123”
base64AuthString = "Basic " + base64.b64encode (Username + ":" +
Password)
import urllib2
objU2opener = urllib2.build_opener ()
objU2opener.addheaders = [('Authorization', base64AuthString)]
objCustomTransport = suds.transport.http.HttpTransport ()
objCustomTransport.urlopener = objU2opener
WSDL = “http://localhost:8080/external/services/DomService?wsdl”
WSDLProxy = suds.client.Client (WSDL, transport = objCustomTransport)
I had suggestions of reading the WSDL using other means and putting it into
a file, which I tried, but not having the authentication issue solved in
suds wouldn’t allow me to call any of the WSDL methods successfully anyway.
The code above was just what I needed!
Cheers
Janet
On 19/10/10 20:37, "Matt C" <mcauthorn(a)gmail.com> wrote:
Janet: I would do some logging on this to see what is going on in
detail. You'll find information on how to do this in the suds
documentation from the site. Also, I've run into bizarre transport
issues with certain versions of urllib2 in the past - rare, but it's
definitely happened and an upgrade fixed things. What version of suds
/ python are you running, by chance?
Also, for basic auth you should be able to simply pass the client
object username/password arguments and Suds will do the right thing
transport-wise. This may be worth another shot (see the notes on buggy
servers and the basic auth RFC).
-Matt
2010/10/8 Janet Valbuena <janet.valbuena(a)tpp.com.au>:
> Dear Daniel
>
> Thanks for assistance, but it still doesn’t make sense that I have to pass
> the WSDL as parameter to connect to a URL via suds.client.Client where I
> will get precisely that same WSDL.
>
> I’m confused.
>
> Thanks anyway. I think I’ll have to get back to SOAPpy unless I hear another
> suggestion to fix my problem.
>
> Regards
>
> Janet
>
>
> On 8/10/10 11:04, "Daniel Rodriguez" <danjrod(a)gmail.com> wrote:
>
> Hi Janet,
>
> I can't really tell you what the realm should be because I haven't found
> myself in such situation
>
> You pass the hacked transport (that should be reading the WSDL from the
> "fileFromU2" file object) because the standard transport included in suds
> assumes a plain HTTP download for WSDL files (unless someone in the list
> proves me wrong and can provide a working example, which would be great)
>
> That's why Joshua suggested that you downloaded the file to disk. I only
> added the means to avoid disk storage by passing the WSDL file object
> directly to a suds compliant transport.
>
> But your problem is that you are apparently unable to download the WSDL file
> (therefore the empty "read"). This is where your problem lies and I guess
we
> can't remotely help you there.
>
> Best regards
>
> Daniel
>
> On Fri, Oct 8, 2010 at 10:37, Janet Valbuena <janet.valbuena(a)tpp.com.au>
> wrote:
>
> Hi Daniel
>
> This still doesn’t make sense.
>
> I understand you’re suggesting this:
>
>
> WSDL = "http://localhost:18080/external/services/DomService?wsdl"
> User = “user1”
> Password = “pass123”
>
> # Is this OK?
> URI = "http://localhost:18080/” <
http://localhost:18080/²>
>
> # What should the realm be? Is this OK?
> Realm = “external/services/DomService”
>
> import urllib2
> auth_handler = urllib2.HTTPBasicAuthHandler()
> auth_handler.add_password(realm=Real, ?uri='your_url_without_the_file_name',
> user=User, passwd=Password)
>
> opener = urllib2.build_opener(auth_handler)
> urllib2.install_opener(opener)
>
> fileFromU2 = urllib2.open(WSDL)
>
> #Note that up to this point, the code doesn’t show any errors but
> fileFromU2.read () is an empty string.
>
> # Then I’m supposed to use the transport hack class:
>
> myClient = suds.client.Client(WSDL, transport=HackTransport(fileFromU2),
> etc)
>
> # The question is, why should I pass fileFromU2 as a transport parameter,
> when what I’m trying to get through calling the Client is precisely that
> WSDL?
>
>
> What I’m really hoping to do (in case I haven’t been clear) is something
> like this:
>
> # Assuming the authorisation issue is solved somehow by producing a ‘t’
> parameter to pass on here:
> myClient = suds.client.Client(WSDL, transport=t)
>
> # Call some of the methods available in the WSDL, for example:
> Result = myClient.createAccount({“name”:”janet”, “phone”: “8989898989”,
> “address”:”12 Victoria St”, “city”:”Manly”, “email”: “janet(a)blahh.xn--com}-ib7a)
>
> Is perhaps suds.client.Client NOT the class I need?
>
> Thanks again for your time and answers in advance.
>
> Cheers
>
> Janet
>
>
> On 7/10/10 21:42, "Daniel Rodriguez" <danjrod(a)gmail.com> wrote:
>
> 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(a)tpp.com.au>
> wrote:
>
> 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(a)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(a)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(a)lists.fedoraproject.org
>
https://admin.fedoraproject.org/mailman/listinfo/suds
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> suds mailing list
> suds(a)lists.fedoraproject.org
>
https://admin.fedoraproject.org/mailman/listinfo/suds
>