我正在尝试将我的Perl SOAP通信应用程序移植到Python等价物,但似乎无法通过urllib2
通过suds
抛出此错误。我的perl soap脚本是:
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
其中myStub
是stubmaker.pl
作为SOAP::Lite
的一部分创建的.pm。
我按如下方式设置了我的python脚本:
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
给了我:
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>
suds
客户端被正确创建,如果我将其打印出来,我会列出预期的方法等。
答案 0 :(得分:5)
看起来urllib2
无法与服务器通信。我怀疑urllib2
是否正在关注HTTPS_PKCS12_*
环境变量。我的猜测是那些特定于你正在使用的Perl库,或Perl本身。 urllib2
根本不进行任何SSL证书验证,如果您希望最好使用pycurl。
这两个问题可能会指出你正确的方向: