[issue26873] xmlrpclib raises when trying to convert an int to string when unicode is available

2016-04-27 Thread Nathan Williams

New submission from Nathan Williams:

I am using xmlrpclib against an internal xmlrpc server.
One of the responses returns integer values, and it raises an exception in 
"_stringify"

The code for _stringify is (xmlrpclib.py:180 in python2.7):

if unicode:
def _stringify(string):
# convert to 7-bit ascii if possible
try:
return string.encode("ascii")
except UnicodeError:
return string
else:
def _stringify(string):
return string


So when "unicode" is available, .encode is called on the parameter (which are 
the returned objects from the server) which fails for ints.

Without the unicode path it works fine, proven with the following monkey-patch:
xmlrpclib._stringify = lambda s: s

I am using the above patch as a workaround, but a fix to the library should be 
straightforward, simply checking for AttributeError in the except clause would 
solve it while retaining the existing functionality.


The traceback:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1387, in _parse_response
p.feed(response)
  File "/usr/lib/python2.6/xmlrpclib.py", line 601, in feed
self._parser.Parse(data, 0)
  File "/usr/lib/python2.6/xmlrpclib.py", line 868, in end
return f(self, join(self._data, ""))
  File "/usr/lib/python2.6/xmlrpclib.py", line 935, in end_struct
dict[_stringify(items[i])] = items[i+1]
  File "/usr/lib/python2.6/xmlrpclib.py", line 176, in _stringify
return string.encode("ascii")
AttributeError: 'int' object has no attribute 'encode'

--
components: Library (Lib)
messages: 264407
nosy: Nathan Williams
priority: normal
severity: normal
status: open
title: xmlrpclib raises when trying to convert an int to string when unicode is 
available
type: crash
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue26873>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26873] xmlrpclib raises when trying to convert an int to string when unicode is available

2016-04-27 Thread Nathan Williams

Nathan Williams added the comment:

I have attached the response.
As it is coming from our UMS, I had to redact a few values, but that shouldn't 
matter.

For reference, they were the host name of my email address, and the hashes of 
passwords etc.
Our UMS is a bit too chatty!

--
Added file: http://bugs.python.org/file42636/pybug.txt

___
Python tracker 
<http://bugs.python.org/issue26873>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26873] xmlrpclib raises when trying to convert an int to string when unicode is available

2016-05-01 Thread Nathan Williams

Nathan Williams added the comment:

Serhiy, that workaround worked for my needs, thanks.

--

___
Python tracker 
<http://bugs.python.org/issue26873>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com