Giter VIP home page Giter VIP logo

python-zeep's Introduction

Zeep: Python SOAP client

A Python SOAP client

Highlights:
  • Compatible with Python 3.7, 3.8, 3.9, 3.10, 3.11 and PyPy3
  • Build on top of lxml, requests and httpx
  • Support for Soap 1.1, Soap 1.2 and HTTP bindings
  • Support for WS-Addressing headers
  • Support for WSSE (UserNameToken / x.509 signing)
  • Support for asyncio using the httpx module
  • Experimental support for XOP messages

Please see for more information the documentation at http://docs.python-zeep.org/

Status

I consider this library to be stable. Since no new developments happen around the SOAP specification it won't be updated that much. Good PR's which fix bugs are always welcome however.

image

image

image

image

Installation

pip install zeep

Note that the latest version to support Python 2.7, 3.3, 3.4 and 3.5 is Zeep 3.4, install via pip install zeep==3.4.0

Zeep uses the lxml library for parsing xml. See https://lxml.de/installation.html for the installation requirements.

Usage

from zeep import Client

client = Client('tests/wsdl_files/example.rst')
client.service.ping()

To quickly inspect a WSDL file use:

python -m zeep <url-to-wsdl>

Please see the documentation at http://docs.python-zeep.org for more information.

Support

If you want to report a bug then please first read http://docs.python-zeep.org/en/master/reporting_bugs.html

Please only report bugs and not support requests to the GitHub issue tracker.

python-zeep's People

Contributors

3bh avatar akeeman avatar apollo13 avatar brunetton avatar btmanm avatar colm29 avatar dankrause avatar dreamsorcerer avatar gopackgo90 avatar hugovk avatar jaceksnet avatar jhorman avatar jjmurre avatar kacah avatar matelakat avatar mcordes avatar mvantellingen avatar nanonyme avatar ngnpope avatar nofalx avatar penguinolog avatar petrvala avatar plaes avatar threepinkapples avatar timrichardson avatar tpazderka avatar vashek avatar vdboor avatar vishu-guntupalli avatar yapith-suplari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-zeep's Issues

Throws ImportError: cannot import name python_2_unicode_compatible

Cannot start the client. Throws the error:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
from zeep import Client
File "/usr/lib/pycharm-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/init.py", line 1, in
from zeep.client import Client # noqa
File "/usr/lib/pycharm-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/client.py", line 4, in
from zeep.wsdl import Document
File "/usr/lib/pycharm-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/init.py", line 1, in
from zeep.wsdl.wsdl import Document # noqa
File "/usr/lib/pycharm-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 12, in
from zeep.wsdl import definitions, http, soap
File "/usr/lib/pycharm-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/definitions.py", line 4, in
from six import python_2_unicode_compatible
ImportError: cannot import name python_2_unicode_compatible

RecursionError: maximum recursion depth exceeded

If I try a
python3 -mzeep http://almdemo.polarion.com/polarion/ws/services/TrackerWebService?wsdl

with the latest master version zeep fails with

...
  File "/home/cheuel/devel/external/python-zeep/src/zeep/xsd/visitor.py", line 116, in visit_import
    schema_node, self.schema._transport, location, self.parser_context)
  File "/home/cheuel/devel/external/python-zeep/src/zeep/xsd/schema.py", line 45, in __init__
    visitor.visit_schema(node)
  File "/home/cheuel/devel/external/python-zeep/src/zeep/xsd/visitor.py", line 82, in visit_schema
    self.process(node, parent=parent)
  File "/home/cheuel/devel/external/python-zeep/src/zeep/xsd/visitor.py", line 40, in process
    result = visit_func(self, node, parent)
  File "/home/cheuel/devel/external/python-zeep/src/zeep/xsd/visitor.py", line 100, in visit_import
    location = absolute_location(location, self.schema._location)
  File "/home/cheuel/devel/external/python-zeep/src/zeep/parser.py", line 50, in absolute_location
    if urlparse(location).scheme:
  File "/usr/lib/python3.5/urllib/parse.py", line 294, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
RecursionError: maximum recursion depth exceeded

'list' object has no attribute 'min_occurs'

I am just about positive that this is not a problem with zeep, just thought I might reach out for help. Just a note, I am trying to wrap a web service which is defined by a WSDL which comes from a company which seems to be known (at least in my circles) for not following standards (or making up their own as they go).

So I need to ask first if it's supported to use a WSDL from the local filesystem instead of from a URL? I didn't see it mentioned in the documentation, but figured I'd give it a try anyway. My code looks like this:

import zeep

client = zeep.Client("./proprietary.wsdl")

At this point I get this traceback:

Traceback (most recent call last):
  File "t.py", line 3, in <module>
    client = zeep.Client('proprietary.wsdl')
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/client.py", line 45, in __init__
    self.wsdl = Document(wsdl, self.transport)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 58, in __init__
    root_definitions = Definition(self, document, self.location)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 147, in __init__
    self.schema = self.parse_types(doc)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 267, in parse_types
    self.wsdl._parser_context, self.location)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/schema.py", line 47, in __init__
    visitor.visit_schema(node)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 94, in visit_schema
    self.process(node, parent=parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 41, in process
    result = visit_func(self, node, parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 157, in visit_include
    return self.visit_schema(schema_node)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 94, in visit_schema
    self.process(node, parent=parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 41, in process
    result = visit_func(self, node, parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 209, in visit_element
    xsd_type = self.process(child, node)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 41, in process
    result = visit_func(self, node, parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 374, in visit_complex_type
    item = self.process(child, node)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 41, in process
    result = visit_func(self, node, parent)
  File "/home/ilovetux/anaconda3/lib/python3.5/site-packages/zeep/xsd/visitor.py", line 733, in visit_choice
    elm.min_occurs = 0
AttributeError: 'list' object has no attribute 'min_occurs'

Honestly, I was expecting to get a connection error or something similar, for which I might simply offer a pull-request, but this seems like it's a problem with the actual WSDL.

Trying to debug the situation, I changed this method to read as follows:

    def visit_choice(self, node, parent):
        """
            <choice
              id = ID
              maxOccurs= (nonNegativeInteger | unbounded) : 1
              minOccurs= nonNegativeInteger : 1
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (element | group | choice | sequence | any)*)
            </choice>
        """
        # There should be only max nodes, first node (annotation) is irrelevant
        children = node.getchildren()
        if children[0].tag == tags.annotation:
            children.pop(0)

        choices = []
        for child in children:
            elm = self.process(child, node)
            try:
                elm.min_occurs = 0
            except:
                print(etree.tostring(child, pretty_print=True).decode("utf-8"))
                raise
            choices.append(elm)
        return xsd_elements.Choice(choices)

And in addition to the above traceback I got this (I'm not sure about license, so I took out anything identifying):

<xsd:sequence xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.proprietary.com/URI">
    <xsd:element name="UniqueElement-1" type="xsd:string"/>
    <xsd:element name="UniqueElement-2" type="xsd:string"/>
    <xsd:element name="UniqueElement-3" type="ns1:CustomType-1"/>
    <xsd:element name="UniqueElement-4" type="ns1:CustomType-2"/>
    <xsd:element name="UniqueElement-5" type="xsd:string"/>
    <xsd:element name="UniqueElement-6" type="xsd:boolean"/>
    <xsd:element name="UniqueElement-7" type="xsd:string" minOccurs="0" maxOccurs="1"/>
    <xsd:element name="UniqueElement-8" type="ns1:CustomType-3" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:element name="UniqueElement-9" type="ns1:CustomType-4" minOccurs="0" maxOccurs="1"/>
    <xsd:element name="UniqueElement-10" type="ns1:CustomType-5" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:element name="UniqueElement-11" type="ns1:CustomType-6" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>

To my untrained eye, it looks ok, but it's too late tonight for me to go pouring over the WSDL/XSD spec. Is the problem amazingly obvious and I'm just missing it?

Parsing of wsdl fails

Hello,
I'm trying to use this SOAP service:

http://destservices.touricoholidays.com/DestinationsService.svc?wsdl

the library fails like this:

from zeep import Client
client = Client('http://destservices.touricoholidays.com/DestinationsService.svc?wsdl')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/client.py", line 45, in __init__
    self.wsdl = Document(wsdl, self.transport)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 59, in __init__
    root_definitions.resolve_imports()
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 185, in resolve_imports
    binding.resolve(self)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/definitions.py", line 187, in resolve
    operation.resolve(definitions)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/soap.py", line 325, in resolve
    self.input.resolve(definitions, self.abstract.input)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/messages.py", line 109, in resolve
    self._info['header'], definitions, parts)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/messages.py", line 128, in _resolve_header
    message = definitions.messages[message_name]
KeyError: u'{http://touricoholidays.com/WSDestinations/2008/08/Contracts}DestinationRequest_Headers'

Any ideas?
Thanks

'Choice' object has no attribute 'qname'

Hi, I'm trying to get some SOAP response using following:

...
motype = 'AVGMultiSC@http://schemas.example.com/ma/APP/'
response = soapclient.service.Get(motype, {'imsi':imsi}, _soapheader = sessionid)
...

But got following issue:

Traceback (most recent call last):
  File "test1.py", line 92, in avgmultisc_get
    response = soapclient.service.Get(motype, {'imsi':imsi}, _soapheader = sessionid)
  File "/usr/lib/python2.7/site-packages/zeep/client.py", line 23, in __call__
    self._proxy._client, self._op_name, args, kwargs)
  File "/usr/lib/python2.7/site-packages/zeep/wsdl/definitions.py", line 292, in send
    client, self.binding_options, operation, args, kwargs)
  File "/usr/lib/python2.7/site-packages/zeep/wsdl/soap.py", line 96, in send
    return self.process_reply(client, operation_obj, response)
  File "/usr/lib/python2.7/site-packages/zeep/wsdl/soap.py", line 127, in process_reply
    return operation.process_reply(doc)
  File "/usr/lib/python2.7/site-packages/zeep/wsdl/soap.py", line 252, in process_reply
    return self.output.deserialize(node)
  File "/usr/lib/python2.7/site-packages/zeep/wsdl/messages.py", line 205, in deserialize
    result.append(part.element.parse(elm, self.wsdl.schema))
  File "/usr/lib/python2.7/site-packages/zeep/xsd/elements.py", line 128, in parse
    return self.type.parse_xmlelement(value, schema)
  File "/usr/lib/python2.7/site-packages/zeep/xsd/types.py", line 248, in parse_xmlelement
    result = field.parse(element, schema)
  File "/usr/lib/python2.7/site-packages/zeep/xsd/elements.py", line 128, in parse
    return self.type.parse_xmlelement(value, schema)
  File "/usr/lib/python2.7/site-packages/zeep/xsd/types.py", line 248, in parse_xmlelement
    result = field.parse(element, schema)
  File "/usr/lib/python2.7/site-packages/zeep/xsd/elements.py", line 128, in parse
    return self.type.parse_xmlelement(value, schema)
  File "/usr/lib/python2.7/site-packages/zeep/xsd/types.py", line 237, in parse_xmlelement
    while field and field.qname != element.tag:
AttributeError: 'Choice' object has no attribute 'qname'

Checked in the xsd and found the below parts that may caused this issue:

...
    <!-- GetAVGMultiSC MOId: imsi or impi MOType: AVG@http://schemas.example.com/ma/APP/ -->
    <!-- GetResponseAVGMultiSC -->
    <xs:element name="GetResponseAVGMultiSC">
        <xs:complexType>
            <xs:sequence>
                <xs:choice>
                    <xs:element name="imsi" type="imsiType" />
                    <xs:element name="impi" type="impiType" />
                </xs:choice>
                <xs:element name="avgEncryptedK" type="avgEncryptedKType" />
                <xs:element name="avgA4KeyInd" type="avgA4KeyIndType" />
                <xs:element name="avgFSetInd" type="avgFSetIndType" />
                <xs:element name="avgAmf" type="avgAmfType" />
                <xs:element name="avgEncryptedOPc" type="avgEncryptedOPcType" minOccurs="0" />
            </xs:sequence>
            <xs:attribute name="imsi" type="imsiType" use="optional">
                <xs:annotation>
                    <xs:appinfo>
                        <jaxb:property name="imsiAttr" />
                    </xs:appinfo>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="impi" type="impiType" use="optional">
                <xs:annotation>
                    <xs:appinfo>
                        <jaxb:property name="impiAttr" />
                    </xs:appinfo>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:schema>

Tried in SOAPUI and it was successful
Attached wsdl/xsd for reference
wsdl_xsd.zip

SSL: CERTIFICATE_VERIFY_FAILED]

My wsdl service is hosted on https
The certificate on the IIS server is a self-signed certificate.
I get this error from zeep.

The command I am running is

python -mzeep https://mysecureservice.svc?wsdl


  File "C:\Python27\lib\site-packages\requests\sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 477, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verif
y failed (_ssl.c:590)

IndexError: list index out of range

Hi,

I just tested your client and got the following error:

File "./soapTest.py", line 6, in <module> client = Client('https://server.tld/someurl?wsdl', wsse=UsernameToken('username', 'password')) File "/usr/local/lib/python3.5/dist-packages/zeep/client.py", line 45, in __init__ self.wsdl = WSDL(wsdl, self.transport) File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/wsdl.py", line 35, in __init__ root_definitions.resolve_imports() File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/wsdl.py", line 138, in resolve_imports binding.resolve(self) File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/definitions.py", line 164, in resolve operation.resolve(definitions) File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/soap.py", line 271, in resolve self.output.resolve(definitions, self.abstract.output) File "/usr/local/lib/python3.5/dist-packages/zeep/wsdl/soap.py", line 369, in resolve part_name = body_info['part'] or part_names[0] IndexError: list index out of range

FacilityService?wsdl.txt

I anonymised the wsdl file. It is only one line. If you need the real server ip I can write you a pm.

Would be glad to hear from you soon, as I really would like to use your client.

Greetings,
Trigrab

response parsing error

Parsing response fails with this wsdl :
http://destservices.touricoholidays.com/DestinationsService.svc?wsdl

and this is response to GetHotelsByDestination:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <HotelsByDestinationResponse xmlns="http://touricoholidays.com/WSDestinations/2008/08/DataContracts">
            <DestinationResult Version="7.123" Culture="en_US" ResultNum="1" ServerTime="6/2/2016 10:29:20 AM">
                <Continent name="Africa" elementType="8" destinationId="1000000" provider="2" status="UpToDate">
                    <Country name="Algeria" elementType="7" destinationId="2000058" provider="2" status="UpToDate">
                        <State name="" elementType="6" destinationId="0" provider="" status="UpToDate" StateShort="">
                            <City name="Ain Benian" elementType="3" destinationId="25647" provider="2" status="UpToDate"
                                  destinationCode="ALG" cityLatitude="36.79650830000000"
                                  cityLongitude="2.93379170000002">
                                <Hotels>
                                    <Hotel hotelId="1323580" hotelName="Hammamet Ain Beniane" destinationId="25647"
                                           hotelLatitude="36.805723853" hotelLongitude="2.958004013"
                                           address="Route Nationale No 11, Grand Rocher, Cap Caxine" zip="16000"
                                           city="Ain Benian" countryCode="DZ" destinationCode="ALG" stars="3"
                                           status="UpToDate" bestVal="0" providerId="2" uploaded="false"/>
                                </Hotels>
                            </City>
                        </State>
                    </Country>
                </Continent>
            </DestinationResult>
        </HotelsByDestinationResponse>
    </s:Body>
</s:Envelope>

error stack trace:

/envs/rooms/local/lib/python2.7/site-packages/zeep/client.py:23: in __call__
    self._proxy._client, self._op_name, args, kwargs)
/envs/rooms/local/lib/python2.7/site-packages/zeep/wsdl/definitions.py:292: in send
    client, self.binding_options, operation, args, kwargs)
/envs/rooms/local/lib/python2.7/site-packages/zeep/wsdl/soap.py:94: in send
    return self.process_reply(client, operation_obj, response)
/envs/rooms/local/lib/python2.7/site-packages/zeep/wsdl/soap.py:125: in process_reply
    return operation.process_reply(doc)
/envs/rooms/local/lib/python2.7/site-packages/zeep/wsdl/soap.py:250: in process_reply
    return self.output.deserialize(node)
/envs/rooms/local/lib/python2.7/site-packages/zeep/wsdl/messages.py:198: in deserialize
    result.append(part.element.parse(elm))
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:212: in parse_xmlelement
    result = field.parse(element)
/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/elements.py:112: in parse
    return self.type.parse_xmlelement(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <zeep.xsd.types.Hotel object at 0x7f30672258d0>
xmlelement = <Element {http://touricoholidays.com/WSDestinations/2008/08/DataContracts}Hotel at 0x7f30676e1488>

    def parse_xmlelement(self, xmlelement):
        instance = self()
        fields = self.properties()
        if not fields:
            return instance

        elements = xmlelement.getchildren()
        attributes = xmlelement.attrib
        if not elements and not attributes:
            return

        fields_map = {f.name: f for f in fields if isinstance(f, Attribute)}
        for key, value in attributes.items():
            field = fields_map.get(key)
            if not field:
                continue
            value = field.parse(value)
            setattr(instance, key, value)

        fields = iter(f for f in fields if not isinstance(f, Attribute))
>       field = next(fields)
E       StopIteration

/envs/rooms/local/lib/python2.7/site-packages/zeep/xsd/types.py:197: StopIteration

This seems to fix it here https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/xsd/types.py#L197:

field = next(fields, None)
if not field:
    return instance

I can't find a right place to do this with tests, sorry.

zeep.exceptions.TransportError: Server returned HTTP status 415 (b'The server cannot service the request because the media type is unsupported.')

Accessing this wsdl - http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc?wsdl
Here's the code -

import zeep
from zeep import Client

location = 'http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc'
wsdl_url = location+'?wsdl'

userID = 'xxxxx'
password = 'xxxx'
passkey = 'xxxxxxxxx'

result = client.service.getPassword(userID, password, passkey)
print(result)

org.xml.sax.SAXException: None is not a legal value

I am using zeep 0.7.0.dev0. The following

from zeep import Client
from zeep.transports import Transport
from zeep.cache import SqliteCache

cache=SqliteCache(persistent=False, timeout=60)

transport = Transport(cache=cache,verify=False)
wsdl='https://webservices.netsuite.com/wsdl/v2016_1_0/netsuite.wsdl'
client=Client(wsdl,transport=transport)

Passport=client.get_type('ns0:Passport')

RecordRef=client.get_type('ns0:RecordRef')

myrole=RecordRef(internalId='1111')

passport=Passport(account='123456',
                       email='[email protected]',
                       password='password',
                       role=myrole
                       )

response=client.service.login(passport)

gives this error:

zeep.exceptions.Fault: org.xml.sax.SAXException: None is not a legal value for {urn:types.core_2016_1.platform.webservices.netsuite.com}RecordType

My understanding is that service does not expect the passed attributes with None values:

<ns0:role internalId="1111" externalId="None" type="None" typeId="None" scriptId="None"/>

If you directly post the payload without these attributes, it gives correct response about invalid credentials:

import requests

headers={'Content-Type': 'text/xml; charset=utf-8', 
         'SOAPAction': 'login'}

#attrs='externalId="None" type="None" typeId="None" scriptId="None"'
attrs=''

payload="""<?xml version="1.0" ?>
<soap-env:Envelope xmlns:ns0="urn:core_2016_1.platform.webservices.netsuite.com" xmlns:ns1="urn:faults_2016_1.platform.webservices.netsuite.com" xmlns:ns10="urn:support_2016_1.lists.webservices.netsuite.com" xmlns:ns11="urn:types.support_2016_1.lists.webservices.netsuite.com" xmlns:ns12="urn:accounting_2016_1.lists.webservices.netsuite.com" xmlns:ns13="urn:types.accounting_2016_1.lists.webservices.netsuite.com" xmlns:ns14="urn:sales_2016_1.transactions.webservices.netsuite.com" xmlns:ns15="urn:types.sales_2016_1.transactions.webservices.netsuite.com" xmlns:ns16="urn:purchases_2016_1.transactions.webservices.netsuite.com" xmlns:ns17="urn:customers_2016_1.transactions.webservices.netsuite.com" xmlns:ns18="urn:financial_2016_1.transactions.webservices.netsuite.com" xmlns:ns19="urn:bank_2016_1.transactions.webservices.netsuite.com" xmlns:ns2="urn:messages_2016_1.platform.webservices.netsuite.com" xmlns:ns20="urn:inventory_2016_1.transactions.webservices.netsuite.com" xmlns:ns21="urn:types.inventory_2016_1.transactions.webservices.netsuite.com" xmlns:ns22="urn:general_2016_1.transactions.webservices.netsuite.com" xmlns:ns23="urn:customization_2016_1.setup.webservices.netsuite.com" xmlns:ns24="urn:types.customization_2016_1.setup.webservices.netsuite.com" xmlns:ns25="urn:employees_2016_1.lists.webservices.netsuite.com" xmlns:ns26="urn:types.employees_2016_1.lists.webservices.netsuite.com" xmlns:ns27="urn:filecabinet_2016_1.documents.webservices.netsuite.com" xmlns:ns28="urn:types.filecabinet_2016_1.documents.webservices.netsuite.com" xmlns:ns29="urn:website_2016_1.lists.webservices.netsuite.com" xmlns:ns3="urn:common_2016_1.platform.webservices.netsuite.com" xmlns:ns30="urn:types.website_2016_1.lists.webservices.netsuite.com" xmlns:ns31="urn:employees_2016_1.transactions.webservices.netsuite.com" xmlns:ns32="urn:marketing_2016_1.lists.webservices.netsuite.com" xmlns:ns33="urn:types.marketing_2016_1.lists.webservices.netsuite.com" xmlns:ns34="urn:demandplanning_2016_1.transactions.webservices.netsuite.com" xmlns:ns35="urn:types.demandplanning_2016_1.transactions.webservices.netsuite.com" xmlns:ns36="urn:supplychain_2016_1.lists.webservices.netsuite.com" xmlns:ns37="urn:types.supplychain_2016_1.lists.webservices.netsuite.com" xmlns:ns38="urn:types.core_2016_1.platform.webservices.netsuite.com" xmlns:ns39="urn:types.faults_2016_1.platform.webservices.netsuite.com" xmlns:ns4="urn:scheduling_2016_1.activities.webservices.netsuite.com" xmlns:ns40="urn:types.common_2016_1.platform.webservices.netsuite.com" xmlns:ns41="urn:types.purchases_2016_1.transactions.webservices.netsuite.com" xmlns:ns42="urn:types.customers_2016_1.transactions.webservices.netsuite.com" xmlns:ns43="urn:types.financial_2016_1.transactions.webservices.netsuite.com" xmlns:ns44="urn:types.bank_2016_1.transactions.webservices.netsuite.com" xmlns:ns45="urn:types.employees_2016_1.transactions.webservices.netsuite.com" xmlns:ns5="urn:types.scheduling_2016_1.activities.webservices.netsuite.com" xmlns:ns6="urn:communication_2016_1.general.webservices.netsuite.com" xmlns:ns7="urn:types.communication_2016_1.general.webservices.netsuite.com" xmlns:ns8="urn:relationships_2016_1.lists.webservices.netsuite.com" xmlns:ns9="urn:types.relationships_2016_1.lists.webservices.netsuite.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap-env:Header>
                <ns2:applicationInfo/>
        </soap-env:Header>
        <soap-env:Body>
                <ns2:login>
                        <ns2:passport>
                                <ns0:email>[email protected]</ns0:email>
                                <ns0:password>password</ns0:password>
                                <ns0:account>123456</ns0:account>
                                <ns0:role internalId="1111" {0}/>
                        </ns2:passport>
                </ns2:login>
        </soap-env:Body>
</soap-env:Envelope>""".format(attrs)

r=requests.post("https://webservices.netsuite.com/services/NetSuitePort_2016_1",
                headers=headers,
                data=payload,
                verify=False)
print(r.text)

KeyError: 'http://schemas.xmlsoap.org/soap/encoding/'

I'm trying to parse this file: https://gw.anionline.com/transactiongateway-v1.2/messaging.asmx?WSDL

The parsing crashes with a KeyError. Here's the whole output:

$ python -mzeep 'https://gw.anionline.com/transactiongateway-v1.2/messaging.asmx?WSDL'
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/__main__.py", line 73, in <module>
    main(args)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/__main__.py", line 62, in main
    client = Client(args.wsdl_file, transport=transport)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/client.py", line 45, in __init__
    self.wsdl = Document(wsdl, self.transport)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 58, in __init__
    root_definitions = Definition(self, document, self.location)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 148, in __init__
    self.schema = self.parse_types(doc)
  File "/Users/nicd/.../virtualenv/lib/python3.5/site-packages/zeep/wsdl/wsdl.py", line 316, in parse_types
    import_node.set('schemaLocation', schema_ns[namespace])
KeyError: 'http://schemas.xmlsoap.org/soap/encoding/'

I tried with the latest master. Is this a bug in zeep or the WSDL file? I'm not experienced in WSDL so I can't tell if it looks valid.

Cannot set sub-type in sequence

Using sub-types (complex extensions) within a sequence results in a couple of errors:

  • Sequences assume that the input is a mapping
  • xs:type is not written for sequence elements

Here is a gist with a monkey patch that resolves these issues (it doesn't seem to introduce new issues, but I haven't tested it very exhaustively): https://gist.github.com/nicholjy/436ae857c30ae6a5bf8cafdeb7921ca3

I'm traveling now, but I should have time in a week or so to submit a pull request with tests.

Repro:
from lxml import etree
from zeep import xsd

node = etree.fromstring("""
    <?xml version="1.0"?>
    <schema
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            elementFormDefault="qualified"
            targetNamespace="http://tests.python-zeep.org/">
      <complexType name="BaseType" abstract="true">
        <sequence>
          <element name="name" type="xsd:string" minOccurs="0"/>
        </sequence>
      </complexType>
      <complexType name="SubType1">
        <complexContent>
          <extension base="tns:BaseType">
            <attribute name="attr_1" type="xsd:string"/>
          </extension>
        </complexContent>
      </complexType>
      <complexType name="PolySequenceType">
        <sequence>
          <element name="item" type="tns:BaseType" maxOccurs="unbounded" minOccurs="0"/>
        </sequence>
      </complexType>
      <element name="Seq" type="tns:PolySequenceType"/>
    </schema>
    """.strip())

schema = xsd.Schema(node)
seq = schema.get_type('ns0:PolySequenceType')
sub_type = schema.get_type('ns0:SubType1')
value = seq(item=[sub_type(attr_1="test", name="name")])

node = etree.Element('document')
seq.render(node, value)
print(etree.tostring(node))

Ability to control soap-env and ns

I was trying to implement a wsdl request an encountered an issue.

the accpected request should be like:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthenticateRequest soap:mustUnderstand="1" xmlns="http://apitest.trafficvance.com/?v3=campaigns">
<apiKey xmlns="">apikey</apiKey>
</AuthenticateRequest>
</soap:Header>
<soap:Body>
<addCampaign xmlns="http://apitest.trafficvance.com/?v3=campaigns">
<parameters xmlns="">
<campaign>
<name>Test Campaign</name>
<description>This is test</description>
<dailyBudgetSunday>0</dailyBudgetSunday>
<dailyBudgetMonday>0</dailyBudgetMonday>
<dailyBudgetTuesday>0</dailyBudgetTuesday>
<dailyBudgetWednesday>0</dailyBudgetWednesday>
<dailyBudgetThursday>0</dailyBudgetThursday>
<dailyBudgetFriday>0</dailyBudgetFriday>
<dailyBudgetSaturday>0</dailyBudgetSaturday>
</campaign>
</parameters>
</addCampaign>
</soap:Body>
</soap:Envelope>

The request message issued by Zeep looks like:

<soap-env:Envelope xmlns:ns0="http://apitest.trafficvance.com/?v3=campaigns" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<ns0:AuthenticateRequest>
<apiKey>apikey</apiKey>
</ns0:AuthenticateRequest>
</soap-env:Header>
<soap-env:Body>
<ns0:addCampaignRequest>
<parameters>
<campaign>
<name>Test Campaign</name>
<description>This is test</description>
<dailyBudgetSunday>0</dailyBudgetSunday>
<dailyBudgetMonday>0</dailyBudgetMonday>
<dailyBudgetTuesday>0</dailyBudgetTuesday>
<dailyBudgetWednesday>0</dailyBudgetWednesday>
<dailyBudgetThursday>0</dailyBudgetThursday>
<dailyBudgetFriday>0</dailyBudgetFriday>
<dailyBudgetSaturday>0</dailyBudgetSaturday>
</campaign>
</parameters>
</ns0:addCampaignRequest>
</soap-env:Body>
</soap-env:Envelope>

There are a few issues here:

  • <soap-env:... instead of <soap:...
  • extra unnecessary ns0:
  • missing <?xml version="1.0" encoding="utf-8"?>
  • missing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and xmlns:xsd="http://www.w3.org/2001/XMLSchema"

I've looked at the entire source code trying to see if these are controllable, couldn't find anything..

Issue with multiple namespaces

Hi and thanks for the awesome library. We are using zeep for a project that integrates with ID3 Global via SOAP. We instantiate a client from a wsdl file, however the file defines services for different namespaces.

from zeep import Client
soap_client = Client('https://pilot.id3global.com/ID3gWS/ID3global.svc?wsdl')

Now, if we try to use the ID3 global's authenticate method (e.g. soap_client.service.AuthenticateSP(some_data)), spits back an Operation Not Found error.

It seems that soap_client.service uses methods available to some namespaces, but not all.
Looking at the wsdl object gives me some extra info:

soap_client.wsdl.schema._prefix_map

    {
        'ns0': 'http://www.id3global.com/ID3gWS/2013/04/Imports',
        'ns1': 'http://www.id3global.com/ID3gWS/2013/04',
        'ns2': 'http://schemas.microsoft.com/2003/10/Serialization/',
        'ns3': 'http://schemas.microsoft.com/2003/10/Serialization/Arrays',
        'ns4': 'http://schemas.microsoft.com/Message',
        'ns5': 'http://schemas.datacontract.org/2004/07/GlobalCheck.DataLib'
    }

The authenticate sp type seems to be available on namespace 1 auth_type = soap_client.get_element('ns1:AuthenticateSP'), but it seems that in order to use that method I would need to navigate a really complex data structure. For example, :

client.wsdl.services['{http://www.id3global.com/ID3gWS/2013/04}ID3global'].ports.keys()
    ['{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalCredentials',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalCredentials',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalConfig',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalConfig',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalDocImage',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalProfile',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalProfile',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalAuthenticate',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalAuthenticate',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalSearch',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalOrganisation',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalOrganisation',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalMembership',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalMembership',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalSupplier',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalSupplier',
     '{http://www.id3global.com/ID3gWS/2013/04}basicHttpBinding_GlobalCaseManagement',
     '{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalCaseManagement']

Then if I go to soap_client.wsdl.services['{http://www.id3global.com/ID3gWS/2013/04}ID3global'].ports['{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalAuthenticate'].binding I can see:

<Soap12Binding(name=u'{http://www.id3global.com/ID3gWS/2013/04}wsHttpBinding_GlobalAuthenticate', port_type=<PortType(name=u'{http://www.id3global.com/ID3gWS/2013/04}IGlobalAuthenticate')>)>

Now these bindings seem to be the ones that would allow me to use the authenticate sp method (see here http://www.id3globalsupport.com/Website/content/Sample%20Code/Web%20Dev%20Guide%20HTML/html/64401bb3-c606-d2b4-9e49-08cebe9376da.htm) . But I'm still unsure how to use it to make the request.

Can someome help me understand / navigate through this ?

wsdl file throw error No connection adapters were found

I'm tryin to use Zeep library with wsdl file instead of url but it doesn't work for me
here is my code:

import zeep
import os

try:
    wsdl_file = 'test.wsdl'
    base_dir = os.path.dirname(__file__)
    wsdl = 'file://%s' % os.path.abspath(base_dir + "/" + wsdl_file)
    client = zeep.Client(wsdl=wsdl)
except Exception as e:
    print e

ImportError

Hello,

I am getting an error when trying to run the command:

  • from zeep import Client
    The error is:
    ImportError: cannot import name 'python_2_unicode_compatible'

I have tried the installation with both pip and pip3.

Regards,
Payam

Some Types are note decoded correctly

When I try to call a service provided by this WSDL, specifically the getCustomField, the Python objects seem to be of the type "None".

I just printed the return value, which looks like this:

{   'key': None,
    'parentItemURI': 'subterra:data-service:objects:/default/linux${WorkItem}LI-321',
    'value': None}

For debugging purpose I caught the packets send by the server with WireShark:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <getCustomFieldResponse xmlns="http://ws.polarion.com/TrackerWebService-impl">
      <getCustomFieldReturn>
        <ns1:parentItemURI xmlns:ns1="http://ws.polarion.com/TrackerWebService-types">subterra:data-service:objects:/default/linux${WorkItem}LI-321</ns1:parentItemURI>
        <ns2:key xmlns:ns2="http://ws.polarion.com/TrackerWebService-types">solution</ns2:key>
        <ns3:value xmlns:ns3="http://ws.polarion.com/TrackerWebService-types" xmlns:ns4="http://ws.polarion.com/types" xsi:type="ns4:Text">
          <ns4:type xsi:type="xsd:string">text/html</ns4:type>
          <ns4:content xsi:type="xsd:string">Test Solutionย </ns4:content>
          <ns4:contentLossy xsi:type="xsd:boolean">false</ns4:contentLossy>
        </ns3:value>
      </getCustomFieldReturn>
    </getCustomFieldResponse>
  </soapenv:Body>
</soapenv:Envelope>

I can't see any problems with the response, except that the server opens different namespaces for the same namespace. At least for the "key" I would expect that zeep returns the string without hassle.

_soapheader is ignored if SOAP header is empty

I need to add a SOAP header a session ID to do requests. I found in Zeep the ability to add "_soapheader" as kwarg to each request. But if I add a header, it is ignored.
I have created a fix for it. Maybe it is helpful.

Raise an exception for (bad request/internal server error) in Transport class.

In WSDL class we have the following lines:

class WSDL(object):
    def __init__(self, filename, transport):
        self.transport = transport
        self.schema = None
        self.ports = {}
        self.messages = {}
        self.bindings = {}
        self.services = {}
        self.namespaces = []
        self.schema_references = {}

        if filename.startswith(('http://', 'https://')):
            response = transport.load(filename)
            doc = self._parse_content(response)
        else:
            with open(filename, mode='rb') as fh:
                doc = self._parse_content(fh.read())
        ......

Would be great to have transport.load(filename, raise_exception=True)

And in Transport class:

class Transport(object):

    def __init__(self, cache=None, timeout=300):
        self.cache = cache
        self.timeout = timeout

    def load(self, url, raise_exception=False):
        if self.cache:
            response = self.cache.get(url)
            if response:
                return bytes(response)

        response = requests.get(url, timeout=self.timeout)

        if raise_exception and response.status_code in status_code_list:
            raise SomeException('some message')

        if self.cache:
            self.cache.add(url, response.content)

        return response.content

What do you think?

Irregular Authentication with Headers

Hi,

I'm trying to authenticate with Trafficvance API.
for example: http://apitest.trafficvance.com/?v3=campaigns.wsdl

Their API requires and AuthenticateRequest with each request.
Quoting their documentation:

Authentication credentials are required to be specified within the SOAP XML request header. You need to invoke AuthenticateRequest
operation and provide the API key as its only parameter, please see available examples for more details

I can't find any way to use this API with Zeep library.
No matter what I try I get zeep.exceptions.Fault: Access denied, authentication failed

Is it even possible?

How do I represent a global enum in my code?

I have this call being made to a Soap service. This is a call from SoapUI.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wcf="http://wcf42.Services">
   <soapenv:Header/>
   <soapenv:Body>
      <wcf:Authenticate>
         <!--Optional:-->
         <wcf:userName>serviceUser</wcf:userName>
         <!--Optional:-->
         <wcf:userPwd>serviceUserPassword</wcf:userPwd>
         <!--Optional:-->
         <wcf:authenticationMode>Ldap</wcf:authenticationMode>
      </wcf:Authenticate>
   </soapenv:Body>
</soapenv:Envelope>

When I try to pass Ldap as a string, the code fails with this message.

KeyError: u"No such type: u'{http://schemas.datacontract.org/2004/07Test.Framework./SysUtils}GlobalEnums.AuthenticationMode' (Only have {http://Test.Services}ServiceResult)"

Is there any method to resolve this? I have attached the wsdl for this service.

AuthenticateSvc.txt
ateSvc.txt)

NotImplementedError: schemaLocation is required

I can't get rid of the error using following command:

python -mzeep https://online.gls-czech.com/webservices/soap_server.php?wsdl

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File ".../lib/python2.7/site-packages/zeep/__main__.py", line 73, in <module>
    main(args)
  File ".../lib/python2.7/site-packages/zeep/__main__.py", line 62, in main
    client = Client(args.wsdl_file, transport=transport)
  File ".../lib/python2.7/site-packages/zeep/client.py", line 45, in __init__
    self.wsdl = WSDL(wsdl, self.transport)
  File ".../lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 34, in __init__
    root_definitions = Definitions(self, document, self.location)
  File ".../lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 106, in __init__
    self.schema = self.parse_types(doc)
  File ".../lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 229, in parse_types
    self.wsdl._parser_context, self.location)
  File ".../lib/python2.7/site-packages/zeep/xsd/schema.py", line 46, in __init__
    visitor.visit_schema(node)
  File ".../lib/python2.7/site-packages/zeep/xsd/visitor.py", line 82, in visit_schema
    self.process(node, parent=parent)
  File ".../lib/python2.7/site-packages/zeep/xsd/visitor.py", line 40, in process
    result = visit_func(self, node, parent)
  File ".../lib/python2.7/site-packages/zeep/xsd/visitor.py", line 95, in visit_import
    raise NotImplementedError("schemaLocation is required")
NotImplementedError: schemaLocation is required

Any ideas?

Thank you.

Problem sending generated xml's

Hello again
Wll I'm trying to generate xml file then open it and send it using zeep. It's almost working but I have problem with serializing some parameters
The code

f = open("test.xml");
c = client.service.MyMethod(f);
print(c)

Fault code:

zeep.exceptions.Fault: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:Parameter_in_Method.
The InnerException message was 'There was an error deserializing the object of type System.Int32. The value '<_io.TextIOWrapper name='test.xml' mode='r' encoding='cp1250'>' cannot be parsed as the type 'Int32'.'

raw soap call

hi... how can i dump the raw soap call in zeep to see what the actual xml looks like?

thanks...

nillable elements not serialized correctly

Looks like there's an issue with nillable elements where objects that are None get converted to '' which then throws an error when being serialized. Given a message with either of these elements:

<s:element minOccurs="1" maxOccurs="1" name="LongId" nillable="true" type="s:long"/>
<s:element minOccurs="1" maxOccurs="1" name="DateOfBirth" nillable="true" type="s:dateTime"/>

An error will be thrown as follows:

zeep.exceptions.Fault: System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 954). ---> System.FormatException: The string '' is not a valid AllXsd value.
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read10_NullableOfDateTime(Boolean checkType)

I have not dug deeply into the issue but I would assume the same is the case for all types, not just those two.

Usage of _soapheader for adding sessionId in SOAP header

I was trying to perform a simple login and logout with Zeep, the login is successful but the logout is not. I think I got a problem with the SOAP header. When login, I don't need to include a header with SessionId, but for logout I will need to provide the sessionid for the logout, where I have to include SessionId in my SOAP header.

I've read the issue 33 and tried to use _soapheader to include my header. However I can't set value for the SessionId.

response = client.service.Login(username, password)
sid = response.sessionId
request = client.service._binding.create_message('Logout', sid, _soapheader={'SessionId':'123'})
print 'Request is: '
print(etree.tostring(request, pretty_print=True))

The above code gives a header with empty SessionId: (pieces of the response )

...
  <soap-env:Header>
    <ns0:SessionId></ns0:SessionId>
  </sopa-env:Header>
  <soap-env:Body>
    <ns0:Logout>
      <ns0:sessionId>f8836958a9724e1a8da19439d94a428f</ns0:sessionId>
    </ns:0:Logout>
  </soap-env:Body>
...

The soap body part are correct, but the header missing the SessionId value

A correct one should look like:

...
  <soap-env:Header>
    <ns0:SessionId>f8836958a9724e1a8da19439d94a428f</ns0:SessionId>
  </sopa-env:Header>
  <soap-env:Body>
    <ns0:Logout>
      <ns0:sessionId>f8836958a9724e1a8da19439d94a428f</ns0:sessionId>
    </ns:0:Logout>
  </soap-env:Body>
...

Am I not using "_soapheader in a correct way"? Thanks in advance.

Attached wsdl & xsd for reference
wsdl_xsd.zip

BaseRef is an abstract type and cannot be instantiated

The following:

from zeep import Client
from zeep.transports import Transport

transport = Transport(verify=False)
wsdl='https://webservices.netsuite.com/wsdl/v2015_1_0/netsuite.wsdl'
client=Client(wsdl,transport=transport)

RecordRef=client.get_type('ns0:RecordRef')

case_ref=RecordRef(internalId='5000000',type='supportCase')

response=client.service.get(case_ref)

gives this error:

zeep.exceptions.Fault: org.xml.sax.SAXException: {urn:core_2015_1.platform.webservices.netsuite.com}BaseRef is an abstract type and cannot be instantiated

Here is the posted payload. It's missing the type specification and the attributes:

<soap-env:Envelope xmlns:ns20="urn:inventory_2015_1.transactions.webservices.netsuite.com" xmlns:ns17="urn:customers_2015_1.transactions.webservices.netsuite.com" xmlns:ns40="urn:types.common_2015_1.platform.webservices.netsuite.com" xmlns:ns26="urn:types.employees_2015_1.lists.webservices.netsuite.com" xmlns:ns23="urn:customization_2015_1.setup.webservices.netsuite.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="urn:messages_2015_1.platform.webservices.netsuite.com" xmlns:ns41="urn:types.purchases_2015_1.transactions.webservices.netsuite.com" xmlns:ns6="urn:communication_2015_1.general.webservices.netsuite.com" xmlns:ns44="urn:types.bank_2015_1.transactions.webservices.netsuite.com" xmlns:ns8="urn:relationships_2015_1.lists.webservices.netsuite.com" xmlns:ns12="urn:accounting_2015_1.lists.webservices.netsuite.com" xmlns:ns37="urn:types.supplychain_2015_1.lists.webservices.netsuite.com" xmlns:ns3="urn:common_2015_1.platform.webservices.netsuite.com" xmlns:ns18="urn:financial_2015_1.transactions.webservices.netsuite.com" xmlns:ns30="urn:types.website_2015_1.lists.webservices.netsuite.com" xmlns:ns43="urn:types.financial_2015_1.transactions.webservices.netsuite.com" xmlns:ns45="urn:types.employees_2015_1.transactions.webservices.netsuite.com" xmlns:ns35="urn:types.demandplanning_2015_1.transactions.webservices.netsuite.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns31="urn:employees_2015_1.transactions.webservices.netsuite.com" xmlns:ns14="urn:sales_2015_1.transactions.webservices.netsuite.com" xmlns:ns27="urn:filecabinet_2015_1.documents.webservices.netsuite.com" xmlns:ns10="urn:support_2015_1.lists.webservices.netsuite.com" xmlns:ns34="urn:demandplanning_2015_1.transactions.webservices.netsuite.com" xmlns:ns5="urn:types.scheduling_2015_1.activities.webservices.netsuite.com" xmlns:ns24="urn:types.customization_2015_1.setup.webservices.netsuite.com" xmlns:ns29="urn:website_2015_1.lists.webservices.netsuite.com" xmlns:ns32="urn:marketing_2015_1.lists.webservices.netsuite.com" xmlns:ns39="urn:types.faults_2015_1.platform.webservices.netsuite.com" xmlns:ns1="urn:faults_2015_1.platform.webservices.netsuite.com" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns15="urn:types.sales_2015_1.transactions.webservices.netsuite.com" xmlns:ns16="urn:purchases_2015_1.transactions.webservices.netsuite.com" xmlns:ns22="urn:general_2015_1.transactions.webservices.netsuite.com" xmlns:ns36="urn:supplychain_2015_1.lists.webservices.netsuite.com" xmlns:ns7="urn:types.communication_2015_1.general.webservices.netsuite.com" xmlns:ns4="urn:scheduling_2015_1.activities.webservices.netsuite.com" xmlns:ns38="urn:types.core_2015_1.platform.webservices.netsuite.com" xmlns:ns0="urn:core_2015_1.platform.webservices.netsuite.com" xmlns:ns11="urn:types.support_2015_1.lists.webservices.netsuite.com" xmlns:ns13="urn:types.accounting_2015_1.lists.webservices.netsuite.com" xmlns:ns25="urn:employees_2015_1.lists.webservices.netsuite.com" xmlns:ns33="urn:types.marketing_2015_1.lists.webservices.netsuite.com" xmlns:ns9="urn:types.relationships_2015_1.lists.webservices.netsuite.com" xmlns:ns42="urn:types.customers_2015_1.transactions.webservices.netsuite.com" xmlns:ns21="urn:types.inventory_2015_1.transactions.webservices.netsuite.com" xmlns:ns19="urn:bank_2015_1.transactions.webservices.netsuite.com" xmlns:ns28="urn:types.filecabinet_2015_1.documents.webservices.netsuite.com">
    <soap-env:Header><ns2:passport><ns0:email/><ns0:password/><ns0:account/></ns2:passport></soap-env:Header>
    <soap-env:Body>
        <ns2:get>
            <ns2:baseRef/>
        </ns2:get>
    </soap-env:Body>
</soap-env:Envelope>

Below is the payload generated from C# client that works and gives the correct response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <get xmlns="urn:messages_2015_1.platform.webservices.netsuite.com">
            <baseRef xmlns:q1="urn:core_2015_1.platform.webservices.netsuite.com" xsi:type="q1:RecordRef" internalId="5000000" type="supportCase" />
        </get>
    </soap:Body>
</soap:Envelope>

P.S. Thanks for fixing the previous issue :)

Support complex WSDL

Hi,

Does the library support files with complex structure? I'm trying to import a WSDL url and generates me errors.

File "/usr/local/lib/python3.5/dist-packages/zeep-0.5.0.dev0-py3.5.egg/zeep/wsdl/definitions.py", line 103, in parse kwargs[tag_name] = definitions.messages[param_msg.text] KeyError:'{http://www.parkaregroup.com/PublisherService/1.0}IPublishServiceV10_startSession_InputMessage'

Thanks,

wsdl fails to import

Far from a SOAP expert here, so all I can really do is post the fault!
but the following:

from zeep import Client`
wsdl='https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl'
client = zeep.Client(wsdl=wsdl)

fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/zeep/client.py", line 45, in __init__
    self.wsdl = WSDL(wsdl, self.transport)
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 35, in __init__
    root_definitions.resolve_imports()
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/wsdl.py", line 138, in resolve_imports
    binding.resolve(self)
  File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/definitions.py", line 164, in resolve
    self.port_type = definitions.port_types[self.port_name.text]
KeyError: u'{http://www.UKMail.com/Services/Contracts/ServiceContracts}IUKMAuthenticationService'

The wsdl file for this service is:

<?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="UKMAuthenticationService" targetNamespace="http://www.UKMail.com/Services" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:tns="http://www.UKMail.com/Services" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://tempuri.org/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"><wsdl:import namespace="http://tempuri.org/" location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl=wsdl1"/><wsdl:types/><wsdl:service name="UKMAuthenticationService"><wsdl:port name="BasicHttpEndpoint_IUKMAuthenticationService" binding="i0:BasicHttpEndpoint_IUKMAuthenticationService"><soap:address location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc"/></wsdl:port></wsdl:service></wsdl:definitions>

Many thanks for your time

method name or namespace not recognized

This may be a faulty SOAP server but I'm seeing this stack dump

File "./X.py", line 42, in getAlarms
soap_response = client.service.GetCurrentState (sessionName)
File "/usr/local/lib/python2.7/dist-packages/zeep/client.py", line 23, in call
self._proxy._client, self._op_name, args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/definitions.py", line 292, in send
client, self.binding_options, operation, args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/soap.py", line 94, in send
return self.process_reply(client, operation_obj, response)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/soap.py", line 123, in process_reply
return self.process_error(doc)
File "/usr/local/lib/python2.7/dist-packages/zeep/wsdl/soap.py", line 202, in process_error
detail=fault_node.find('detail'))
zeep.exceptions.Fault: Method 'ns0:GetCurrentState' not implemented: method name or namespace not recognized

for this code fragment

def getAlarms ():
    wsdl = 'data/AlarmSoap.wsdl'
    sessionName = ""

    client = zeep.Client (wsdl=wsdl)
    client.set_address('AlarmSoap', 'AlarmSoap', url)

    # GetCurrentState(sessionName: xsd:string) -> GetCurrentStateResponse
    soap_response = client.service.GetCurrentState (sessionName)
    print (soap_response)

WSDL attached
AlarmSoap.txt

Nested Type is send as "pretty print" of Python Structure

I try to set a nested Type with Python Zeep. But the send Content to the Server seems to be the Pretty Print from Python of the Structure. Specifically I try to do a "setCustomField" of the WSDL:

edp = Client(url, username, password)
edp.service.getCustomField(uri, "solution")

new_value_type = edp.get_type("{http://ws.polarion.com/types}Text")                                                                                                                                       
val = new_value_type(type = "text/html", content="This is a first Test", contentLossy=False)                                                                                                                         
new_solution_type = edp.get_type("{http://ws.polarion.com/TrackerWebService-types}CustomField")                                                                                                           
sol = new_solution_type(key="solution", parentItemURI=uri, value=val)                                                                                                                                           

edp.service.setCustomField(sol, _soapheader=sh)             

And here the content of the Packet send to the server:

<soap-env:Envelope xmlns:ns0="http://ws.polarion.com/TrackerWebService-impl" xmlns:ns1="http://ws.polarion.com/types" xmlns:ns2="http://ws.polarion.com/TrackerWebService-types" xmlns:ns3="http://ws.polarion.com/ProjectWebService-types" xmlns:ns4="http://ws.polarion.com/PlanningWebService-types" xmlns:ns5="http://ws.polarion.com/TrackerWebService" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap-env:Header><pols:sessionID xmlns:pols="http://ws.polarion.com/session">2803906303964766973</pols:sessionID></soap-env:Header>
<soap-env:Body>
<ns0:setCustomField>
<ns0:customField>
<ns2:parentItemURI>subterra:data-service:objects:/default/sw${WorkItem}LI-66</ns2:parentItemURI><ns2:key>solution</ns2:key>
<ns2:value>{   'content': 'This is a first Test',
    'contentLossy': False,
    'type': 'text/html'}</ns2:value>
</ns0:customField>
</ns0:setCustomField>
</soap-env:Body>
</soap-env:Envelope>

The server responds then "Value can't be null". As it seems, the value is only a pretty print of the Python structure.

Am I doing something wrong, when I construct the structure with Zeep?

Debug Mode

Is it possible to create a "debug mode"?

I want to be able to see the XML request before it is sent.
It very hard to debug requests without actually seeing it..

Improve examples and documentation

At the moment the documentation is quite limited to trivial cases. It would be nice to see more examples, such as:

WSDL snippet:

<xsd:compexType name="foo">
    <xsd:sequence>
        <xsd:element name="bar"/>

<xsd:element name="element1">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="name1" type="tns:foo" minOccurs="0" maxOccurs="unbounded"/>

How I'm trying to use it with the library:

foo1 = client.get_type('ns1:foo')
foo1.bar = "this is an attribute"
element1 = client.get_element('ns1:element')
# now the fields() method shows there's a list in element1, also invoking element1() prints
# {    'item':  [] }
# but, how do I add 'foo1' to 'element1'?
element1.properties().append(foo1)  # no error, but doesn't show

Perhaps activate the wiki and let users contribute? I'd be happy to help.

zeep.exceptions.TransportError: Server returned HTTP status 415 (b'The server cannot service the request because the media type is unsupported.')

Trying to access this web service :

from zeep import Client
from zeep.transports import Transport

location = 'http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc'
wsdl_url = location+'?wsdl'

transport = Transport(verify=False)
client = Client(wsdl_url, transport=transport)

userID = '1003201'
password = 'test@123'
passkey = 'test123'

result = client.service.getPassword(userID, password, passkey)
print(result)

This is the trace I get when I run this script :

Traceback (most recent call last):
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/zeep/wsdl/soap.py", line 85, in process_reply
doc = fromstring(response.content)
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/defusedxml/lxml.py", line 140, in fromstring
rootelement = _etree.fromstring(text, parser, base_url=base_url)
File "lxml.etree.pyx", line 3103, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70569)
File "parser.pxi", line 1828, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106403)
File "parser.pxi", line 1716, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:105194)
File "parser.pxi", line 1086, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:99876)
File "parser.pxi", line 580, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:94350)
File "parser.pxi", line 690, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:95786)
File "parser.pxi", line 620, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:94853)
lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "zeep_test.py", line 19, in
result = client.service.getPassword(userID, password, passkey)
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/zeep/client.py", line 24, in call
self._proxy._client, self._op_name, args, kwargs)
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/zeep/wsdl/definitions.py", line 284, in send
client, self.binding_options, operation, args, kwargs)
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/zeep/wsdl/soap.py", line 73, in send
return self.process_reply(client, operation_obj, response)
File "/Users/mohit/anaconda3/envs/py34/lib/python3.4/site-packages/zeep/wsdl/soap.py", line 89, in process_reply
% (response.status_code, response.content))
zeep.exceptions.TransportError: Server returned HTTP status 415 (b'The server cannot service the request because the media type is unsupported.')

What's going wrong here ?

Better distinction between global elements and complex types

Take for example the following schema

<?xml version="1.0"?>
<schema>
  <element name="SomeRequest">
    <complexType>
      <all>
        <element ref="tns:account"/>
      </all>
    </complexType>
  </element>
  <complexType name="account">
    <sequence>
      <element name="balance" type="int"/>
    </sequence>
  </complexType>
  <element name="account">
    <complexType>
      <sequence>
        <element name="id" type="int"/>
        <element name="user" type="string"/>
      </sequence>
    </complexType>
  </element>
</schema>

The only way to create this request is by using:

client.get_element('tns:account').type(id=1, user='foo')
client.service.SomeRequest(obj)

Using the following would cause an error in this case.

client.get_type('tns:account')(id=1, user='foo')
client.service.SomeRequest(obj)

So this means the user needs to have an understanding of the xsd schema, which should not be the case.

Support for HTTP basic authentication

Hello,

Is there a plan to support HTTP basic authentication when using the HTTP binding?

The aging suds library provides this as optional parameters to the client class (https://fedorahosted.org/suds/wiki/Documentation#HTTPAUTHENTICATION).

Here's a stab at a solution I made. I decided to add an http_auth parameter to the transport and pass that straight through to request.get/post

mcordes@a2b5d98

I hope that's useful (and I'm happy to send a PR if that's reasonable) and I've love to see this functionality get added in whatever capacity.

error parsing wsdl

hello, again I've encountered some cursed wsdl which won't parse, please have a look:

from zeep import Client
>>> client = Client('http://demo-hotelws.touricoholidays.com/HotelFlow.svc?wsdl')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/client.py", line 45, in __init__
    self.wsdl = Document(wsdl, self.transport)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 58, in __init__
    root_definitions = Definition(self, document, self.location)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 146, in __init__
    self.parse_imports(doc)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 236, in parse_imports
    wsdl = Definition(self.wsdl, document, location)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 149, in __init__
    self.messages = self.parse_messages(doc)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/wsdl.py", line 337, in parse_messages
    msg = definitions.AbstractMessage.parse(self, msg_node)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/wsdl/definitions.py", line 61, in parse
    part_element = definitions.schema.get_element(part_element)
  File "/envs/roomstorm/local/lib/python2.7/site-packages/zeep/xsd/schema.py", line 136, in get_element
    name.text, ', '.join(self._elements), self))
KeyError: "No such element: u'{http://tourico.com/webservices/hotelv3}SearchHotels' (Only have ) (from: <Schema(location='http://demo-hotelws.touricoholidays.com/HotelFlow.svc?wsdl=wsdl0')>)"

SSL Self signed certificate error

Hello,
First thank for awesome library. Second is there possibility to turn off ssl signature verification?

Becasue I have this error:

Traceback (most recent call last):
File "", line 1, in
File "C:\Python34\lib\site-packages\zeep\client.py", line 45, in init
self.wsdl = WSDL(wsdl, self.transport)
File "C:\Python34\lib\site-packages\zeep\wsdl\wsdl.py", line 32, in init
document = self._load_content(location)
File "C:\Python34\lib\site-packages\zeep\wsdl\wsdl.py", line 79, in _load_content
location, self.transport, self._parser_context, self.location)
File "C:\Python34\lib\site-packages\zeep\parser.py", line 39, in load_external
response = transport.load(url)
File "C:\Python34\lib\site-packages\zeep\transports.py", line 19, in load
response = requests.get(url, timeout=self.timeout, verify=self.verify)
File "C:\Python34\lib\site-packages\requests\api.py", line 67, in get
return request('get', url, params=params, *_kwargs)
File "C:\Python34\lib\site-packages\requests\api.py", line 53, in request
return session.request(method=method, url=url, *_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, *_send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, *_kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

regression with getting types

before commit b04dba2 this was working ok:

client = Client('http://destservices.touricoholidays.com/DestinationsService.svc?wsdl')
type = client.get_type('ns1:Destination')

after this error is raised:

work/room/room/tourico/api.py:24: in __init__
    self.service_arg_type = self.client.get_type(method_arg_name)
/envs/room/local/lib/python2.7/site-packages/zeep/client.py:99: in get_type
    return self.wsdl.schema.get_type(name)
/envs/room/local/lib/python2.7/site-packages/zeep/xsd/schema.py:111: in get_type
    name = self._create_qname(name)
/envs/room/local/lib/python2.7/site-packages/zeep/xsd/schema.py:162: in _create_qname
    return etree.QName(name)
src/lxml/lxml.etree.pyx:1831: in lxml.etree.QName.__init__ (src/lxml/lxml.etree.c:61175)
    ???
src/lxml/apihelpers.pxi:1626: in lxml.etree._tagValidOrRaise (src/lxml/lxml.etree.c:32662)
    ???
E   ValueError: Invalid tag name u'ns1:Destination'

after little investigation I've found that the client.wsdl.schema._prefix_map contained this:
{'ns0': 'http://touricoholidays.com/WSDestinations/2008/08/Contracts/Imports', 'ns1': 'http://touricoholidays.com/WSDestinations/2008/08/DataContracts', 'ns2': 'http://schemas.microsoft.com/2003/10/Serialization/'}

after the commit it's empty.

Error parsing xsd - dependency handling

Hi there

first of all thanks a lot for this great project!

It looks like the xsd parser expects sequential order of dependencies inside the xsd file, which isn't the case in my xsd i'm forced to use. if i reorder it manually it works like expected.

example xsd given:

<xs:schema xmlns="http://www.swisscom.com/wsg/bb/v29" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.swisscom.com/wsg/bb/v29" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:annotation>
        <xs:documentation>Common types for WSG </xs:documentation>
    </xs:annotation>
    <!-- ********************************************* -->
    <!--             SIMPLE TYPES                      -->
    <!-- ********************************************* -->
    <!-- accessSpeedProfileNrType -->
    <xs:simpleType name="accessSpeedProfileNrType">
        <xs:annotation>
            <xs:documentation>[LOV-ID: 1010] An access speed profile number.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="speedProfileNrType"/>
    </xs:simpleType>
    <!-- speedProfileNrType -->
    <xs:simpleType name="speedProfileNrType">
        <xs:annotation>
            <xs:documentation>[LOV-ID: 1010] A speed profile number.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="lovType"/>
    </xs:simpleType>
    <!-- lovType -->
    <xs:simpleType name="lovType">
        <xs:annotation>
            <xs:documentation>The abstract LOV base type.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:totalDigits value="3"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

This fails in xsd/schema.py with:

KeyError: "No such type: '{http://www.swisscom.com/wsg/bb/v29}speedProfileNrType' (Only have )"

if i reorder it like this:

<xs:schema xmlns="http://www.swisscom.com/wsg/bb/v29" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.swisscom.com/wsg/bb/v29" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:annotation>
        <xs:documentation>Common types for WSG </xs:documentation>
    </xs:annotation>
    <!-- ********************************************* -->
    <!--             SIMPLE TYPES                      -->
    <!-- ********************************************* -->
    <!-- lovType -->
    <xs:simpleType name="lovType">
        <xs:annotation>
            <xs:documentation>The abstract LOV base type.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:totalDigits value="3"/>
        </xs:restriction>
    </xs:simpleType>
    <!-- speedProfileNrType -->
    <xs:simpleType name="speedProfileNrType">
        <xs:annotation>
            <xs:documentation>[LOV-ID: 1010] A speed profile number.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="lovType"/>
    </xs:simpleType>
    <!-- accessSpeedProfileNrType -->
    <xs:simpleType name="accessSpeedProfileNrType">
        <xs:annotation>
            <xs:documentation>[LOV-ID: 1010] An access speed profile number.</xs:documentation>
        </xs:annotation>
        <xs:restriction base="speedProfileNrType"/>
    </xs:simpleType>
</xs:schema>

it works like expected.

additional info:

  • the wsdl loads with SoapUI and suds like expected.
  • the same error also appears when a complexType refers to a simpleType before it is defined inside the xsd
  • tested with the current master.zip installed i a virtualenv with python3.5

Pass a dict as parameter in a operation

Hi,

First of all, I'd like to say that this is a very nice soap library for python.

<message name="SearchFilter">
<part name="user" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="parameters" type="tns:searchFilterIn"/>
</message>

We have the following code:

from zeep import Client
client = Client("http://some-soap-endpoint?WSDL") 
parameters_info = {"type": "some-value"}
client.service.SearchFilter("user", "password'" parameters=parameters_info)

The question is how can I pass these parameters? Is this correct? Thanks

AttributeError: 'QName' object has no attribute 'name'

I trying to use zeep to get access to Polarion. When I try to inspect the wsdl file, I get an error:

python3 -mzeep http://almdemo.polarion.com/polarion/ws/services/TrackerWebService?wsdl

Prefixes:
     ns0: http://ws.polarion.com/TrackerWebService-impl
     ns2: http://ws.polarion.com/TrackerWebService-types
     ns1: http://ws.polarion.com/types
     ns4: http://ws.polarion.com/PlanningWebService-types
     ns3: http://ws.polarion.com/ProjectWebService-types
     ns5: http://ws.polarion.com/TrackerWebService

Global types:
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/zeep/__main__.py", line 73, in <module>
    main(args)
  File "/usr/lib/python3/dist-packages/zeep/__main__.py", line 68, in main
    client.wsdl.dump()
  File "/usr/lib/python3/dist-packages/zeep/wsdl/wsdl.py", line 57, in dump
    for type_obj in sorted(type_instances, key=lambda k: six.text_type(k)):
  File "/usr/lib/python3/dist-packages/zeep/wsdl/wsdl.py", line 57, in <lambda>
    for type_obj in sorted(type_instances, key=lambda k: six.text_type(k)):
  File "/usr/lib/python3/dist-packages/zeep/xsd/types.py", line 208, in __str__
    return '%s(%s)' % (self.__class__.__name__, self.signature())
  File "/usr/lib/python3/dist-packages/zeep/xsd/types.py", line 157, in signature
    for name, element, container in self.fields()
  File "/usr/lib/python3/dist-packages/zeep/xsd/types.py", line 157, in <listcomp>
    for name, element, container in self.fields()
  File "/usr/lib/python3/dist-packages/zeep/xsd/elements.py", line 81, in _signature
    self.type.name, '[]' if self.max_occurs != 1 else ''
AttributeError: 'QName' object has no attribute 'name'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.