0

I'm trying to use ZEEP to do SOAP requests.

I got this request:

def status(request, IP):
    URL = "http://" + IP + "/Service"
    session = Session()
    session.auth = HTTPBasicAuth('username', 'password')
    client = Client(URL,
                    transport=Transport(session=session), strict=False)

    response = client.service.Method1(request={'getList'})

    return response

But I'm hitting the error missing wsdl:service definitions in the WSDL.

I'm stuck and can't find any more way to fault search. Got any ideas?

Edit for context. This is a hardcoded request that works and I'm trying to do with zeep:

 def GetList(session, IP):        

        request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'
        request = request + '<soapenv:Header>'
        request = request + '<session>' + session + '</session>'
        request = request + ' </soapenv:Header>'
        request = request + ' <soapenv:Body>'
        request = request + '<getList/>'
        request = request + '</soapenv:Body>'
        request = request + '</soapenv:Envelope>'

        request = u"""""" + request + """""".format()

        encoded_request = request.encode('utf-8')

        headers = {"Host": ""+ IP +"",
                   "Content-Type": "text/xml; charset=UTF-8",
                   "Content-Length": str(len(encoded_request)),
                   "SOAPAction": ""}

        response = requests.post(url="http://"+ url +"/Service",
                                 headers=headers,
                                 data=encoded_request,
                                 verify=False)

        return response.content

Edit 2. Add the wsdl

<?xml version="1.0" encoding="UTF-8"?>    
-<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:intf="http://xml.apache.org/axis/wsdd/ " xmlns:impl="http://xml.apache.org/axis/wsdd/ " xmlns:apachesoap="http://xml.apache.org/xml-soap" targetNamespace="http://xml.apache.org/axis/wsdd/ ">    
-<wsdl:types>    
-<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.apache.org/axis/wsdd/ ">    
<element type="xsd:anyType" name="parseMessage"/>    
<element type="xsd:anyType" name="parseMessageReturn"/>    
</schema>    
</wsdl:types>    
-<message name="parseMessageResponse">    
<part name="parseMessageReturn" element="impl:parseMessageReturn"/>    
</message>    
-<message name="parseMessageRequest">    
<part name="part" element="impl:parseMessage"/>    
</message>    
-<portType name="MessageHandlerProxy">    
-<operation name="parseMessage">    
<input name="parseMessageRequest" message="impl:parseMessageRequest"/>    
<output name="parseMessageResponse" message="impl:parseMessageResponse"/>    
</operation>    
</portType>    
-<binding type="impl:HandlerProxy" name="ServiceBinding">    
<wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>    
-<operation name="parseMessage">    
<wsdlsoap:operation soapAction=""/>    
-<input name="parseMessageRequest">    
<wsdlsoap:body use="literal" namespace="http://xml.apache.org/axis/wsdd/ "/>    
</input>    
-<output name="parseMessageResponse">    
<wsdlsoap:body use="literal" namespace="http://xml.apache.org/axis/wsdd/ "/>    
</output>    
</operation>    
</binding>    
-<service name="ProxyService">    
-<port name="Service" binding="impl:ServiceBinding">    
<wsdlsoap:address location="http://ip.ip.ip.ip/Service"/>    
</port>    
</service>    
</definitions>
sumpen
  • 503
  • 6
  • 19
  • Can you confirm that are passing the right URL? Did you try this URL with a SOAP client and worked fine? It should be in the format ``http://some_IP_here/Service?wsdl`` – Galil Sep 12 '17 at 11:17
  • @Galil I can open the url i explorer, but not Chrome. Chrome throws an error: _error on line 2 at column 207: xmlns:impl: 'http://xml.apache.org/axis/wsdd/ ' is not a valid URI_ And I run: `python -mzeep URL?wsdl` Get same error as chrome: _zeep.exceptions.XMLSyntaxError: Invalid XML content received (xmlns:impl: 'http://xml.apache.org/axis/wsdd/ ' is not a valid URI, line 2, column 207)_ But I get no error if I run `python -mzeep --no-strict URL?wsdl` – sumpen Sep 12 '17 at 11:47
  • did you add ``?wsdl`` at the URL variable? Like: ``URL = "http://" + IP + "/Service?wsdl"``. Did you test your function again? – Galil Sep 12 '17 at 11:53
  • @Galil Yes. That throws the error: AttributeError _Service has no operation 'Method1'_ Method1 was something that was in the zeep docs. Don't know what it means. But tested to remove it and get this error when removed: TypeError _'ServiceProxy' object is not callable_ – sumpen Sep 12 '17 at 12:17

1 Answers1

1

You have to add the ?wsdl at the end of your URL variable.

Also, the way you are making the call is not correct. A call to getList should look like:

def status(request, IP):
    URL = "http://" + IP + "/Service?wsdl"
    session = Session()
    session.auth = HTTPBasicAuth('username', 'password')
    client = Client(URL,
                    transport=Transport(session=session), strict=False)

    response = client.service.getList([add the arguments here])

    return response
Galil
  • 859
  • 2
  • 16
  • 40
  • This trows me the error: AttributeError _Service has no operation 'getList'_ It also says this: _During handling of the above exception (No such operation 'getList' on {http://xml.apache.org/axis/wsdd/ }MessageServiceBinding), another exception occurred:_ Which is strange since it's not suppose to be _http://xml.apache.org/axis/wsdd/_ – sumpen Sep 12 '17 at 13:16
  • The error you are getting means that there is not such a call. Is there a call ``getList``? Is it spelled correctly? I used the ``getList`` call as an example. You should replace it with the name of the API call you want to use. – Galil Sep 12 '17 at 13:19
  • Yes, I'm positive it's correct. I have updated the question with some context. That is a example of a hardcoded request that is working. And you can see the being called. So I can do the requests with hardcoded code. But not with zeep. And I can't figure out what I'm doing wrong. I really appreciate all your help you are providing. – sumpen Sep 12 '17 at 13:33
  • If I understand correctly, the ``getList`` does not have any arguments. Then ``client.service.getList()`` should work fine. If not, try to debug what ``client.service`` returns. – Galil Sep 12 '17 at 16:01
  • Hey. I added the WSDL to the question. I can't seem to get client.service to return anything. When returning client.service I get: _'Client' object has no attribute 'get'_ The hardcoded example I added before in the question, is working. But before that I have to send a hardcoded login to get a sessionID. Oterwise I cant request anything. But if I request without a valis sessionID, I get a response that I need to have a session. All the requests I do with zeep only response errors. So something is fundamentally wrong with what I do. – sumpen Sep 13 '17 at 11:22
  • I manage to get a return with suds. It says this if I just call client: _Suds ( https://fedorahosted.org/suds/ ) version: 0.6 Service ( MessageHandlerProxyService ) tns="http://xml.apache.org/axis/wsdd/ " Prefixes (0) Ports (1): (MessageService) Methods (1): parseMessage(xs:anyType parseMessage) Types (0):_ – sumpen Sep 13 '17 at 11:35