Search code examples
pythonpython-3.xsoapwsdlzeep

Api Request WSDL Python


I am trying to make an api connection via wsdl-soap in Python.

Here are the codes I used.

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))

The offical documentation suggests:

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

Service Method Signature: CategoryServiceResponse getCategories(int startOffSet, int rowCount, boolean withSpecs, boolean withDeepest, boolean withCatalog, String lang)

Request Example

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

However I can't achieve to get any data from the source. I am getting errors like:

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)
>>> 

Any help (new library suggestions, code correction etc.) will be appriciated.

Thanks in advance!


Solution

  • I finally solved my own problem.. The thing that I have missed is that it was needing an authentication layer.

    Here are the codes for those who may need to solve similar problems.

    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..))
    

    Here is the source I made use of..