sagarnigade / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

"UnicodeDecodeError: 'ascii' codec can't decode byte " when handle unicode with WSDL call #91

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. set up a wsdl that require unicode parameters
2. the code as bleow, call the wsdl func. There are Chinese or other unicode in 
the parameters.
        client = SoapClient(wsdl=wsdl_uri, trace=True)
        response = client.XmlSubmit(identity, request, filter)

What is the expected output? What do you see instead?
I want the output of the service, but got the below information:
  File "ysta.py", line 22, in get_xml
    response = client.XmlSubmit(identity, request, filter)
  File "/usr/local/lib/python2.7/site-packages/pysimplesoap/client.py", line 140, in <lambda>
    return lambda *args, **kwargs: self.wsdl_call(attr,*args,**kwargs)
  File "/usr/local/lib/python2.7/site-packages/pysimplesoap/client.py", line 289, in wsdl_call
    response = self.call(method, *params)
  File "/usr/local/lib/python2.7/site-packages/pysimplesoap/client.py", line 185, in call
    self.xml_response = self.send(method, self.xml_request)
  File "/usr/local/lib/python2.7/site-packages/pysimplesoap/client.py", line 211, in send
    location,"POST", body=xml, headers=headers )
  File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1597, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1345, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1282, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/local/lib/python2.7/httplib.py", line 958, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python2.7/httplib.py", line 992, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python2.7/httplib.py", line 812, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 2388: 
ordinal not in range(128)
Uncaught exception. Entering post mortem debugging

What version of the product are you using? On what operating system?
python 2.7.3 / pysimplesoap 1.0.5a/ httplib2 / CentOS 6 

Please provide any additional information below.
Trace into the lib, and got the solution.
Pysimplesoap lib get the wsdl location and action from the wsdl returned xml.  
And in unicode. So the location and headers parameters  is unicode str. When 
"msg += messgae_body" called in httplib, the message_body was attempted to 
decoded by 'ascii' codec. Then fail. 

Solution:
convert the location and action into str in clienty.py. Please advice or fix in 
the trunk. 

 194c194
<         location = "%s" % self.location #?op=%s" % (self.location, method)

---
>         location = str("%s" % self.location) #?op=%s" % (self.location, 
method)
196c196
<             soap_action = self.action 

---
>             soap_action = str(self.action)
198c198
<             soap_action = self.action+method

---
>             soap_action = str(self.action)+method

Original issue reported on code.google.com by sfw...@gmail.com on 31 Jan 2013 at 2:01

GoogleCodeExporter commented 9 years ago
Great!

Could you provide a patch and test case?

Original comment by reingart@gmail.com on 1 Feb 2013 at 5:30

GoogleCodeExporter commented 9 years ago
The patch file is attached using hg diff with current master. Sorry about the 
test case. I cannot easily build a test case without leaking out some 
authentication information. 

Original comment by sfw...@gmail.com on 4 Feb 2013 at 2:15

Attachments: