我正在尝试使用Python使用SAP Web服务。我能够得到响应,但是当我在其中调用方法时,得到响应错误。 如何使用Python调用Web服务方法?
Python代码:
from suds.client import Client
import json
wsdl_url = "<URL>"
client = Client(url = wsdl_url, username = "<username>", password = "<password>")
print(client)
x = client.service[0].Methods[1]
print(x)
输出:
Suds ( https://github.com/cackharot/suds-py3 ) version: 1.3.3.0 IN build: 20170311
Service ( ziot_service1 ) tns="urn:sap-com:document:sap:rfc:functions" Prefixes (1)
ns0 = "urn:sap-com:document:sap:rfc:functions" Ports (2):
(ziot_service1)
Methods (1):
ZIOT_SERVICE1()
Types (3):
char10
char4
date10
(ziot_service1_soap12)
Methods (1):
ZIOT_SERVICE1()
Types (3):
char10
char4
date10
--------------------------------------------------------------------------------
Traceback (most recent call last): File "webservice0.py", line 6, in <module>
x = client.service[0].Methods[1] File "C:\Users\Sid-PC\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\client.py", line 511, in __getattr__
return self[name] File "C:\Users\Sid-PC\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\client.py", line 524, in __getitem__
raise MethodNotFound(qn) suds.MethodNotFound: Method not found: 'ziot_service1.ziot_service1.Methods'
我要去哪里错了,怎么解决?
答案 0 :(得分:0)
必须使用方法名称。您可以尝试以下方法:
x = client.service[0].ZIOT_SERVICE1()
我也会检查这一点,以防万一:
x = client.service[1].ZIOT_SERVICE1()
调用WS方法的另一种方法是通过其名称检索它:
ziot_method = getattr(client.service[0],'ZIOT_SERVICE1')
x = ziot_method()