This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Nathan Williams
Recipients Nathan Williams
Date 2016-04-28.01:49:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 ( in python2.7):

if unicode:
    def _stringify(string):
        # convert to 7-bit ascii if possible
            return string.encode("ascii")
        except UnicodeError:
            return string
    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 "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.6/", line 1489, in __request
  File "/usr/lib/python2.6/", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/", line 1387, in _parse_response
  File "/usr/lib/python2.6/", line 601, in feed
    self._parser.Parse(data, 0)
  File "/usr/lib/python2.6/", line 868, in end
    return f(self, join(self._data, ""))
  File "/usr/lib/python2.6/", line 935, in end_struct
    dict[_stringify(items[i])] = items[i+1]
  File "/usr/lib/python2.6/", line 176, in _stringify
    return string.encode("ascii")
AttributeError: 'int' object has no attribute 'encode'
Date User Action Args
2016-04-28 01:49:22Nathan Williamssetrecipients: + Nathan Williams
2016-04-28 01:49:22Nathan Williamssetmessageid: <>
2016-04-28 01:49:22Nathan Williamslinkissue26873 messages
2016-04-28 01:49:21Nathan Williamscreate