如何在Python中调用Web服务功能



我正在尝试使用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:UsersSid-PCAppDataLocalProgramsPythonPython37libsite-packagessudsclient.py", line 511, in __getattr__
    return self[name]   File "C:UsersSid-PCAppDataLocalProgramsPythonPython37libsite-packagessudsclient.py", line 524, in __getitem__
    raise MethodNotFound(qn) suds.MethodNotFound: Method not found: 'ziot_service1.ziot_service1.Methods'

我要去哪里,我该如何修复?

有必要使用方法名称。您可以尝试一下:

x = client.service[0].ZIOT_SERVICE1()

我还会检查一下,以防万一:

x = client.service[1].ZIOT_SERVICE1()

调用WS方法的另一种方法是通过其名称检索:

ziot_method = getattr(client.service[0],'ZIOT_SERVICE1')
x = ziot_method()

相关内容

  • 没有找到相关文章

最新更新