Using jsonrpclib in windows

242 views
Skip to first unread message

staeff

unread,
Dec 20, 2010, 4:13:06 PM12/20/10
to JSONRPClib (Python)
Hi,
I'm trying to learn python, writing a small jsonrpc client.
Your library is doing well on linux, however on my Windows client I'm
getting following error message:

python 2.6.6 (2.7 also)

>>> import jsonrpclib
>>> server = jsonrpclib.Server('http://192.168.220.222:8080/jsonrpc')
>>> server.JSONRPC.Ping()

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
server.JSONRPC.Ping()
File "C:\Python26\lib\site-packages\jsonrpclib\jsonrpc.py", line
220, in __call__
return self.__send(self.__name, kwargs)
File "C:\Python26\lib\site-packages\jsonrpclib\jsonrpc.py", line
167, in _request
rpcid=rpcid, version=self.__version)
File "C:\Python26\lib\site-packages\jsonrpclib\jsonrpc.py", line
444, in dumps
return jdumps(request, encoding=encoding)
File "C:\Python26\lib\site-packages\jsonrpclib\jsonrpc.py", line 90,
in jdumps
return json.dumps(obj, encoding=encoding)
File "C:\Python26\lib\json\__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "C:\Python26\lib\json\encoder.py", line 367, in encode
chunks = list(self.iterencode(o))
File "C:\Python26\lib\json\encoder.py", line 309, in _iterencode
for chunk in self._iterencode_dict(o, markers):
File "C:\Python26\lib\json\encoder.py", line 275, in
_iterencode_dict
for chunk in self._iterencode(value, markers):
File "C:\Python26\lib\json\encoder.py", line 294, in _iterencode
yield encoder(o)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c in position 1:
invalid start byte
>>>

HP

unread,
Feb 11, 2011, 9:27:51 AM2/11/11
to JSONRPClib (Python)
Hi,

we use jsonrpclib in our project and have the same issue. I have
figured it out what's going on.

Json rpc generates a random id for each request, and uses the
string.lowercase attribute to get the letters of the id. But the
locale settings overwrite this property and the id become invalid. For
example using jsonrpc from Maya on my system the string.lowercase has
the following value:

abcdefghijklmnopqrstuvwxyzšśťžźłµąşľżßŕáâăäĺćçčéęëěíîďđńňóôőöřůúűüýţ

The relevant code is in the jsonrpclib.py at line 365:

def random_id(length=8):
import string
import random
random.seed()
choices = string.lowercase+string.digits
return_id = ''
for i in range(length):
return_id += random.choice(choices)
return return_id

The solution would be to use the string.ascii_lowercase attribute
instead of string.lowercase which contains only the ascii letters.
Josh, could you please add this fix to the next release?

Thanks,
Peter

Josh Marshall

unread,
Feb 11, 2011, 4:58:11 PM2/11/11
to jsonr...@googlegroups.com
Great catch!

I'll try to push that update this weekend. Can you go ahead and file it as an issue (with the recommended solution) at  http://github.com/joshmarshall/jsonrpclib for posterity's sake?

Thanks!

Josh Marshall

HP

unread,
Feb 13, 2011, 10:04:30 AM2/13/11
to JSONRPClib (Python)
Hi,

issue is added: https://github.com/joshmarshall/jsonrpclib/issues#issue/4

Peter

On Feb 11, 10:58 pm, Josh Marshall <catchj...@gmail.com> wrote:
> Great catch!
>
> I'll try to push that update this weekend. Can you go ahead and file it as
> an issue (with the recommended solution) athttp://github.com/joshmarshall/jsonrpclib<https://github.com/joshmarshall/jsonrpclib>
> for
> posterity's sake?
>
> Thanks!
>
> Josh Marshall
>
Reply all
Reply to author
Forward
0 new messages