Porting perl soap application to python
perl, python, soap
Solution
Looks like `urllib2` is unable to communicate with the server. I doubt `urllib2` is paying any attention to the `HTTPS_PKCS12_*` environment variables. My guess would be that those are specific to the Perl library you were using, or to Perl itself. `urllib2` doesn't do any SSL cert validation at all, if you want that you're better off using pycurl.
These two questions might point you in the right direction:
- Suds over https with cert
- Validate SSL certificates with Python
Problem
I'm trying to port my Perl SOAP communication application to a Python equivalent at the moment but can't seem to get past this error that `urllib2` is throwing via `suds`. My working perl soap script is: ``` use myStub; $ENV{HTTPS_PKCS12_FILE} = '/path/to/certificate'; $ENV{HTTPS_PKCS12_PASSWORD} = 'password'; my $client = new myStub; my $output = $client->foo('test', 'something'); print $output ``` where `myStub` is the .pm created by `stubmaker.pl` as part of `SOAP::Lite`. and I set up my python script as follows: ``` from suds.client import Client import os os.environ['HTTPS_PKCS12_FILE'] = '/path/to/certificate' os.environ['HTTPS_PKCS12_PASSWORD'] = 'password' client = Client('file:WSDL') output = client.service.foo('test', 'something') print output ``` which gives me: ``` File "test.py", line 12, in <module> output = client.service.foo('test', 'something') File "/usr/lib/python2.6/site-packages/suds/client.py", line 542, in __call__ return client.invoke(args, kwargs) File "/usr/lib/python2.6/site-packages/suds/client.py", line 602, in invoke result = self.send(soapenv) File "/usr/lib/python2.6/site-packages/suds/client.py", line 643, in send reply = transport.send(request) File "/usr/lib/python2.6/site-packages/suds/transport/https.py", line 64, in send return HttpTransport.send(self, request) File "/usr/lib/python2.6/site-packages/suds/transport/http.py", line 77, in send fp = self.u2open(u2request) File "/usr/lib/python2.6/site-packages/suds/transport/http.py", line 118, in u2open return url.open(u2request, timeout=tm) File "/usr/lib64/python2.6/urllib2.py", line 391, in open response = self._open(req, data) File "/usr/lib64/python2.6/urllib2.py", line 409, in _open '_open', req) File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib64/python2.6/urllib2.py", line 1198, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib64/python2.6/urllib2.py", line 1165, in do_open raise URLError(err) urllib2.URLError: <urlopen error [Errno 8] _ssl.c:490: EOF occurred in violation of protocol> ``` The `suds` client is getting created fine and if I print it out, I get the expected methods being listed etc.