Reputation: 31
I'm trying to get zeep to open a WSDL that has bindings with dot in the beginning of the name and get a ValueError: Invalid tag name '.USXMLWSSoapBinding' error message.
The WSDL defines the binding name as:
<wsdl:binding name=".USXMLWSSoapBinding" type="impl:USXMLWS">
I can get it to work with other languages and libraries, but python and zeep don't seem to agree with me with:
python -mzeep <wsdl>
or
import zeep
client = zeep.Client('https://example.com/service.wsdl')
Upvotes: 3
Views: 2275
Reputation: 440
You can patch the crashing behavior of Zeep through unittest.mock
from unittest import mock
from zeep import Client
def my_as_qname(value, nsmap, target_namespace=None):
value = value.strip()
if '/' in value: # This is my fix for slash in value
value = value.replace('/', '-')
# More stuff that i removed in this snippet
with mock.patch('zeep.utils.as_qname', side_effect=my_as_qname):
client = Client(wsdl)
In my case, the failing WSDL is french postoffice « La Poste » new Colissimo webservice. https://ws.colissimo.fr/sls-ws/SlsServiceWS/2.0?wsdl
I guess other people trying to use Zeep with it will stumble on the same issue.
Upvotes: 3
Reputation: 9
Zeep uses lxml to parse the wsdl. Binding names that start with dot appear to be not strictly XML compliant. If you can't change the binding name, you could possibly work around this by editing lib\site-packages\zeep\utils.py
along the lines of what was done for https://github.com/mvantellingen/python-zeep/issues/594
For example:
...
def qname_attr(node, attr_name, target_namespace=None):
value = node.get(attr_name)
if value is not None:
return as_qname(value, node.nsmap, target_namespace)
def as_qname(value, nsmap, target_namespace=None):
"""Convert the given value to a QName"""
value = value.strip() # some xsd's contain leading/trailing spaces
#KLUDGE for bindingnames that start with '.'
if value.startswith('.'):
print("Stripping leading '.' from:", value)
value = value.lstrip('.')
if ':' in value:
prefix, local = value.split(':')
...
Note this may have unintended side-effects; This worked for me but I haven't done much testing, YMMV. You could make it more selective by testing value for specific substrings, or making the change in qname_attr
and testing attr_name for 'name' too.
I ran into something similar recently with a binding name that had '/' in it.
I know very little about SOAP and/or XML, but as far as I can make out a binding name is a QName, which consists of an optional prefix and a localpart (separated by :). The prefix and localpart are NCNames; An NCName is an XML Name without ':'; A Name is an Nmtoken with a restricted set of initial characters, including the full stop (dot).
I'm not sure if these w3.org references are the most up-to-date, but they are the ones that turned up when I searched:
https://www.w3.org/TR/wsdl20/#component-Binding
The properties of the Binding component are as follows:
{name} REQUIRED. An xs:QName ...
https://www.w3.org/TR/xml-names/#ns-qualnames
Qualified Names In XML documents conforming to this specification, some names (constructs corresponding to the nonterminal Name) MUST be given as qualified names, defined as follows: Qualified Name [7] QName ::= PrefixedName | UnprefixedName [8] PrefixedName ::= Prefix ':' LocalPart [9] UnprefixedName ::= LocalPart [10] Prefix ::= NCName [11] LocalPart ::= NCName
https://www.w3.org/TR/xml-names/#NT-NCName
[4] NCName ::= Name - (Char* ':' Char*) /* An XML Name, minus the ":" */
https://www.w3.org/TR/REC-xml/#NT-Name
A Name is an Nmtoken with a restricted set of initial characters.] Disallowed initial characters for Names include digits, diacritics, the full stop and the hyphen.
What is an xs:NCName type and when should it be used?
Practical restrictions of an NCName The practical restrictions of NCName are that it cannot contain several symbol characters like :, @, $, %, &, /, +, ,, ;, whitespace characters or different parenthesis. Furthermore an NCName cannot begin with a number, dot or minus character although they can appear later in an NCName.
Upvotes: 0