mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 586 forks source link

TypeError: cannot pickle 'lxml.etree.QName' object in header #1258

Open ryanlewist opened 3 years ago

ryanlewist commented 3 years ago

I am having trouble making a request. The error I get is TypeError: cannot pickle 'lxml.etree.QName' object. I saw that there was a similar issue some time ago: https://github.com/mvantellingen/python-zeep/issues/842, but the bug-reporter moved on and the issue was closed before it was resolved.

Running: zeep==4.1.0 lxml==4.6.3

python version is 3.8.3 (also tried on 3.9.7)

Here is the script that fails. Note that the UN/PW and request are not relevant at this stage because the error occurs before the request is made.

from lxml import etree
from zeep import Client

wsdl = 'https://services.mycccportal.com/CCCOne/RF/ONEService/PartnerGatewayService.asmx?WSDL'
client = Client(wsdl)

_soapheaders = client.get_element('ns1:Security')
_soapheaders({'Username': 'A_Username', 'Password': 'A_Password'})

request = 'a string'

# result = client.service.Execute(request=request, _soapheaders=_soapheaders)

node = client.create_message(client.service, 'Execute', request=request, _soapheaders=_soapheaders)
print(etree.tostring(node, pretty_print=True))
BlackMooseNicky commented 2 years ago

I ran into the same issue but was able to workaround it by creating a custom xsd element.

This is described in section 3 of this page: https://docs.python-zeep.org/en/master/headers.html