PDA

View Full Version : Python SOAP client problem


zolakt
2010-04-09, 10:58
Hi,

I'm having a lot of problem making a SAOP client in Python.
I have tried various methods, but non of them seems to work for me.

I have a .Net web service, available from an IIS server on another machine.
I can access it trough browser, and everything works fine.

The function I need to call is .RunTranslate.
It takes one string argument inText, and 2 custom enumeration arguments, inLang and outLang (I suppose they are serialized/deserialized as string), a returns one string value as translation.

Now, what I have tried:

1. SOAPy library
import soap
server = soap.get_proxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl','wsdl')
translation = server.RunTranslate(inText="translate this", inLang="English", outLang="German")

I get the following error:
File "/usr/lib/python2.5/site-packages/soap.py", line 263, in __init__
sys.exit(1)
NameError: global name 'sys' is not defined

I tried to make the proxy with sdl, not wsdl, with:
server = soap.get_proxy('http://192.168.1.72/sts/TranslatorService.asmx?SDL','sdl')

But then I get this error
File "/usr/lib/python2.5/site-packages/_xmlplus/dom/ext/reader/PyExpat.py", line 65, in fromStream
success = self.parser.ParseFile(stream) xml.parsers.expat.
ExpatError: mismatched tag: line 61, column 16

2. ZSI library
from ZSI import ServiceProxy
server = ServiceProxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl')
translation = server.RunTranslate(inText="translate this", inLang="English", outLang="German")

This produces the following error
File "./main.py", line 25, in translate
server = ServiceProxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl')
TypeError: 'module' object is not callable

3. Sending HTTP POST request with httplib
import httplib
httpServ = httplib.HTTPConnection("http://192.168.1.72", 80)
httpServ.connect()
httpServ.request('POST', '/sts/TranslatorService.asmx?op=RunTranslate','inText=tr anslat+this&inLang=English&outLang=Croatian')

response = httpServ.getresponse()
if response.status == httplib.OK:
print (response.read())
httpServ.close()

The error:
File "/usr/lib/python2.5/httplib.py", line 667, in connect
socket.SOCK_STREAM):
socket.gaierror: (-3, 'Temporary failure in name resolution')

4. Sending HTTP POST request with urllib, urllib2
I don't have a code for this, I deleted it. But it produced similar errors like httplib

I'm working in Maemo5 scratchbox.
I have noticed that scratchbox has Internet connection, because I can use apt-get, with no problems.
But it doesn't render HTML, because I can't open anything in its browser.
Maybe this is creating all the problems, or am I doing something completely wrong.

Any help would be greatly appreciated.

mece
2010-04-09, 11:07
Hi,

I'm having a lot of problem making a SAOP client in Python.
I have tried various methods, but non of them seems to work for me.

I have a .Net web service, available from an IIS server on another machine.
I can access it trough browser, and everything works fine.

The function I need to call is .RunTranslate.
It takes one string argument inText, and 2 custom enumeration arguments, inLang and outLang (I suppose they are serialized/deserialized as string), a returns one string value as translation.

Now, what I have tried:

1. SOAPy library
import soap
server = soap.get_proxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl','wsdl')
translation = server.RunTranslate(inText="translate this", inLang="English", outLang="German")

I get the following error:
File "/usr/lib/python2.5/site-packages/soap.py", line 263, in __init__
sys.exit(1)
NameError: global name 'sys' is not defined
[...]


perhaps some bug in the soap library there?
missing an import sys?

mece
2010-04-09, 11:23
You could try suds instead. Seems pretty straight forward. Here's some documentation: https://fedorahosted.org/suds/wiki/Documentation

python-suds is the package.

viraptor
2010-04-09, 11:29
2. ZSI library
from ZSI import ServiceProxy
server = ServiceProxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl')
translation = server.RunTranslate(inText="translate this", inLang="English", outLang="German")

This produces the following error
File "./main.py", line 25, in translate
server = ServiceProxy('http://192.168.1.72/sts/TranslatorService.asmx?wsdl')
TypeError: 'module' object is not callable


Not sure about the rest, but this should be imported as:
from ZSI.ServiceProxy import ServiceProxy

Ah - and httplib should be without "http://...":

httpServ = httplib.HTTPConnection("192.168.1.72", 80)

zolakt
2010-04-09, 12:33
perhaps some bug in the soap library there?
missing an import sys?
sys is imported into script. But its not in the library.
Anyway it isn't very imported because it fails at this line
nodes = domobj.getElementsByTagName('definitions')
if len(nodes) == 0:
print "Couldn't find definitions tag!"
sys.exit(1)



Not sure about the rest, but this should be imported as:
from ZSI.ServiceProxy import ServiceProxy

Changed it and it hives a different error.
File "build/bdist.linux-i686/egg/ZSI/wstools/WSDLTools.py", line 1116, in getAddressBinding
ZSI.wstools.WSDLTools.WSDLError: No address binding found in port.


Ah - and httplib should be without "http://...":
httpServ = httplib.HTTPConnection("192.168.1.72", 80)
When I do this, it doesn't give an error. But it returns nothing.
However if I omit the first / in the uri path, it returns Bad Request HTTP Error.

zolakt
2010-04-09, 13:58
I got it working with httplib2
I just send a request, get a XML reply.

Then I just have to parse it correctly