0
我遇到了Python SOAP請求的問題。 到目前爲止,我測試了兩個python SOAP客戶端庫:SUDS和pysimplesoap。 無論對於下面的例子很好地工作:Python SOAP客戶端嵌套請求
from suds.client import Client
from pysimplesoap.client import SoapClient, SoapFault
# suds example
url = "http://www.webservicex.net/geoipservice.asmx?WSDL"
client = Client(url, cache=None)
print client.service.GetGeoIP((ip))
# pysimplesoap example
client = SoapClient(wsdl="http://www.webservicex.net/geoipservice.asmx?WSDL")
# call the remote method
response = client.GetGeoIP(("10.0.1.152"))
print response
都工作得不錯,給我預期的響應:
{'GetGeoIPResult': {'ReturnCodeDetails': 'Success', 'IP': '10.0.1.152', 'ReturnCode': 1, 'CountryName': 'Reserved', 'CountryCode': 'ZZZ'}}
隨着UI SOAP測試PROGRAMM的要求是這樣的:
-<soap:Envelope>
-<soap:Body>
-<GetGeoIP>
<IPAddress>("10.0.1.152")</IPAddress>
</GetGeoIP>
</soap:Body>
</soap:Envelope>
現在的問題是,我需要通過SOAP與另一個WS聯繫,但這不起作用。與UI SOAP程序它的工作原理(密鑰和標記可以爲空),看起來像:
-<soap:Envelope>
-<soap:Body>
-<getNews>
-<shrequest>
<data>{'account_number':202VA7, 'track_nr':1757345939}</data>
<function>getnewsdata</function>
<keys/>
<token/>
</shrequest>
</getNews>
</soap:Body>
</soap:Envelope>
但我的代碼不起作用:
url = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client = Client(url, cache=None)
data = "{'account_number':202VA7, 'track_nr':1757345939}"
function = "getnewsdata"
keys = ""
token = ""
shrequest = [data,function,keys,token]
response = client.service.getNews(shrequest)
print response
我得到:
ValueError('Invalid Args Structure. Errors: %s' % errors)
ValueError: Invalid Args Structure. Errors:
如何嵌套我的請求?
你可能想改變'{「ACCOUNT_NUMBER」:202VA7'爲'{「ACCOUNT_NUMBER」:'202VA7'' – thefourtheye
感謝您的答覆,但由於數據是整個字符串,一點不物。這是我用於UI程序的相同參數,並且在那裏工作得很好。 – gulden