mvantellingen / python-zeep

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

UnicodeDecodeError - and I don't know what to do #1141

Open EnzephaloN opened 4 years ago

EnzephaloN commented 4 years ago

Hello

I'm using zeep for (trying to) talk to webservices. The client runs on linux, the services on Windows - maybe thats important.

When I call a service, I get errors like: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte or UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd9 in position 4: invalid continuation byte

my code (the needed parts):

class GWS:
   def __init__:
       self.config = configparser.ConfigParser()
       self.config.read(join(os.path.dirname(os.path.realpath(__file__)), "configuration.ini"))
       self.gClient = zeep.Client(wsdl=self.config["G"]["g_wsdl_url"])
...
self.gWS = GWS()
self.gService = self.gWS.gClient.service
...
arf = self.g.GetAbrResultFiles(tfile.DT_ID, self.s.secret)

last lines of error

  File "/home/schulzj/.local/lib/python3.8/site-packages/zeep/xsd/types/builtins.py", line 47, in xmlvalue
    return value.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xec in position 0: invalid continuation byte
da1910 commented 4 years ago

In this case it looks like you may be passing an input that is not correctly decoded, is the error in the line:

arf = self.g.GetAbrResultFiles(tfile.DT_ID, self.s.secret)

If so then make sure that if you are reading either argument from a file you are correctly passing the encoding. The first error message suggests that your file has a BOM which isn't being removed correctly, I would start with trying "utf-16" or "utf-8-sig".

EnzephaloN commented 4 years ago

Hello @da1910 Thanks for your reply. tfile.DT_ID is integer, so no need/possibility to encode. self.s.secret ist object of type byte as a result of "from Crypto.Cipher import DES"

I realy do not know what to do...

da1910 commented 3 years ago

Ok, in that case are you able to provide the relevant portion of the WSDL file? It's challenging to offer more specific advice without it.

EnzephaloN commented 3 years ago

Hello

Here some parts of WSDL. I renamed namespace and location because of "security".


<wsdl:definitions name="AuthPortalService" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="http://G.Online" location="http://xxx.xx.xx.x/OnlineWebClientTest/PortalService.svc?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:binding name="BasicHttpBinding_IPortalService" type="i0:IPortalService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
...
<wsdl:operation name="GetAbrResultFiles">
<soap:operation soapAction="http://G.KvOnline/IPortalService/GetAbrResultFiles" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
...
<wsdl:service name="AuthPortalService">
<wsdl:port name="BasicHttpBinding_IPortalService" binding="tns:BasicHttpBinding_IPortalService">
<soap:address location="http://xxx.xx.xx.xx/OnlineWebClientTest/PortalService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
alfremedpal commented 3 years ago

@EnzephaloN Did you manage to resolve your issue? I'm having a similar problem. In my case however, the input for the SOAP service is a Python dictionary and I let zeep handle the conversion. I suspect some values in that said dict may have special characters, but I don't know if I should encode the input or what the clients returns. According to my logs the header in the xml request I send to the service has the encoding utf-8, so I'm not sure what it is happening. And same as in your case, client is Linux (well, a Lambda really), and the services run on a Windows server.

EnzephaloN commented 3 years ago

@alfremedpal Sorry, but I didn't get it to work. Meanwhile I have buried this project.