Api 请求 WSDL Python

Api Request WSDL Python

我正在尝试通过 Python 中的 wsdl-soap 建立 api 连接。

这是我使用的代码。

import zeep
wsdl = 'http://dev.gittigidiyor.com:8080/listingapi/ws/CategoryService?wsdl'
client = zeep.Client(wsdl=wsdl)


send_data=[{

'cat:getCategories' :[

{
'startOffSet' : 0,
'rowCount' : 4,
'withSpecs':'true',
'withDeepest':'true',
'withCatalog':'true',
'lang':'tr'
}
     ] } ]


print(client.service.getCategories(send_data))

官方documentation建议:

WSDL 地址: http://dev.gittigidiyor.com:8080/listingapi/ws/CategoryService?wsdl

服务方法签名: CategoryServiceResponse getCategories(int startOffSet, int rowCount, boolean withSpecs, boolean withDeepest, boolean withCatalog, String lang)

请求示例

<cat:getCategories>
   <startOffSet>0</startOffSet>
   <rowCount>4</rowCount>
   <withSpecs>true</withSpecs>
   <withDeepest>true</withDeepest>
   <withCatalog>true</withCatalog>
   <lang>tr</lang>
</cat:getCategories>

但是我无法从源中获取任何数据。我收到如下错误:

Traceback (most recent call last):
  File "/Users/maydin/Desktop/z.py", line 22, in <module>
    print(client.service.getCategories(send_data))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/proxy.py", line 42, in __call__
    self._op_name, args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", line 115, in send
    options=options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", line 68, in _create
    serialized = operation_obj.create(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/wsdl/definitions.py", line 200, in create
    return self.input.serialize(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/wsdl/messages/soap.py", line 65, in serialize
    self.body.render(body, body_value)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/elements/element.py", line 191, in render
    self._render_value_item(parent, value, render_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/elements/element.py", line 215, in _render_value_item
    return self.type.render(node, value, None, render_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/types/complex.py", line 253, in render
    element.render(parent, element_value, child_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/elements/indicators.py", line 241, in render
    element.render(parent, element_value, child_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/elements/element.py", line 185, in render
    self.validate(value, render_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zeep/xsd/elements/element.py", line 236, in validate
    "Missing element %s" % (self.name), path=render_path)
zeep.exceptions.ValidationError: Missing element rowCount (getCategories.rowCount)
>>> 

任何帮助(新库建议、代码更正等)都将得到应用。

提前致谢!

我终于解决了我自己的问题。我错过的是它需要一个身份验证层。

以下是可能需要解决类似问题的人的代码。

from requests import Session
from requests.auth import HTTPBasicAuth 
from zeep import Client
from zeep.transports import Transport

session = Session()
session.auth = HTTPBasicAuth('user_name', 'password')

client = Client('wsdl_url',
    transport=Transport(session=session))


print(client.service.service_name(parameter1,parameter2,parameter3..))

这里是source我用的..