3

我目前正在尝试将我的 Perl SOAP 通信应用程序移植到 Python 等价物,但似乎无法克服urllib2通过suds. 我的工作 perl 肥皂脚本是:

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

作为 .pm 的一部分myStub创建的 .pm 在哪里?stubmaker.plSOAP::Lite

我设置我的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很好,如果我打印出来,我会列出预期的方法等。

4

1 回答 1

5

看起来urllib2无法与服务器通信。我怀疑urllib2是否注意HTTPS_PKCS12_*环境变量。我的猜测是那些特定于您正在使用的 Perl 库或 Perl 本身。urllib2根本不做任何 SSL 证书验证,如果你想要你最好使用pycurl

这两个问题可能会为您指明正确的方向:

于 2013-02-18T16:03:34.223 回答