简体   繁体   English

用suds为SOAP编写Python客户端

[英]Writing python client for SOAP with suds

I want to convert a perl SOAP client into a python SOAP client. 我想将perl SOAP客户端转换为python SOAP客户端。 The perl client is initialized like Perl客户端像

$url = 'https://host:port/cgi-devel/Service.cgi';
$uri = 'https://host/Service';

my $soap = SOAP::Lite 
    -> uri($uri)
    -> proxy($url);

I tried to replicate this in python 2.4.2 with suds 0.3.6 doing 我试图用suds 0.3.6在python 2.4.2中复制它

from suds.client import Client

url="https://host:port/cgi-devel/Service.cgi" 
client=Client(url)

However when running this python script I get the error 但是在运行此python脚本时出现错误

suds.transport.TransportError: HTTP Error 411: Length Required

Is it because of https or what might be the problem? 是因为https还是问题所在? Any help would be greatly appreciated! 任何帮助将不胜感激!

urllib2 module doesn't add Content-Length (required for POST method) header automatically when Request object is constructed manually as suds does. 当请求对象像suds一样手动构造时, urllib2模块不会自动添加Content-Length(对于POST方法是必需的)标头。 You have to patch suds, probably suds.transport.HttpTransport.open() method or suds.transport.Request class. 您必须修补suds.transport.HttpTransport.open() ,可能是suds.transport.HttpTransport.open()方法或suds.transport.Request类。

I had the same error, then switched to using a local WSDL file, this worked: 我遇到了同样的错误,然后切换到使用本地WSDL文件,此方法有效:

import suds
wsdl = 'file:///tmp/my.wsdl'
client = suds.client.Client(wsdl, username='lbuser', password='lbpass', location='https://path.to.our.loadbalancer:9090/soap')

You should ask this in the suds's mailing list. 您应该在肥皂水的邮件列表中询问。 This library is under development, is open source, and the authors are very keen to get feedback from the users. 该库正在开发中,是开源的,作者非常渴望获得用户的反馈。

Your code looks fine, this could be an error of the wsdl itself or of the suds library, therefore I encourage you to ask the author directly (after having checked with other wsdls that your installation is correct). 您的代码看起来不错,这可能是wsdl本身或suds库的错误,因此,我建议您直接询问作者(在与其他wsdls确认安装正确之后)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM