簡體   English   中英

用suds為SOAP編寫Python客戶端

[英]Writing python client for SOAP with suds

我想將perl SOAP客戶端轉換為python SOAP客戶端。 Perl客戶端像

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

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

我試圖用suds 0.3.6在python 2.4.2中復制它

from suds.client import Client

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

但是在運行此python腳本時出現錯誤

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

是因為https還是問題所在? 任何幫助將不勝感激!

當請求對象像suds一樣手動構造時, urllib2模塊不會自動添加Content-Length(對於POST方法是必需的)標頭。 您必須修補suds.transport.HttpTransport.open() ,可能是suds.transport.HttpTransport.open()方法或suds.transport.Request類。

我遇到了同樣的錯誤,然后切換到使用本地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')

您應該在肥皂水的郵件列表中詢問。 該庫正在開發中,是開源的,作者非常渴望獲得用戶的反饋。

您的代碼看起來不錯,這可能是wsdl本身或suds庫的錯誤,因此,我建議您直接詢問作者(在與其他wsdls確認安裝正確之后)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM