problem: non-ascii data and xmlrpmlib.py

"Dr. Martin Korff" <[email protected]>
Newsgroups gmane.comp.cms.opengroupware.xmlrpc.devel
Message-ID <[email protected]>
Hi everybody!

First I'd like to thank the responsibles for opensourcing the OGO-system.
Second I'd like to thank those who are on the front line, like Helge,
for their strong and ongoing support, always in a timely and contructive
manner. So, let me bother you once more. 

Well maybe this time you'll tell me to go elsewhere with
my off-topic, python-only related noise ;-).
However, a number of attempts in trying to find out the deeper reason
or just a working implementation failed. So here are the details.

My problem seems to be in the 'xmlrpclib.py' library:
See my script 'test.py' below. Effectively it reads a specific entry
in the Person-Database and reinserts the very same data again.
The problem appears because the city of the first address associated
with my 'Test'-Person is 'São Paulo', i.e. containing an 'a' with a '~'
above - a very common Portuguese accent - thus making this record one
the repr. of which cannot be interpreted as Ascii-chars. 

Funny, but I believe that the very same situation should arise in the 
German language context on letters like ä, ö, and ü (umlaute).
However, I did not test this.

	Any hints? 

		Martin

P.S.: A similar, if not the same (don't remember exactly), error 
occured using python V.2.2 (Mandrake 9.1) - which made me upgrade to V2.3


#------------- begin script


!/usr/bin/env python
# -*- coding: utf-8 -*-

# createCSV.py

import xmlrpclib, string, base64
import sys, codecs
from pprint import *

# settings
url      = "http://ogoserver/RPC2"
login    = 'root'
password = 'password'

if __name__ == '__main__':

        server = xmlrpclib.Server(url,login=login,password=password)
        query  = {
                        'qualifier' : "firstname like 'Test'",
                        'fetchLimit' : '1',
                       }
        idList = server.person.fetchIds(query)

        if idList:
                count = 1
                for idBatch in range(0,len(idList),10):
                        persons = 
server.person.getById(idList[idBatch:idBatch+10])
                        for person in persons:
                                result = server.person.update(person)

#------------ end script

The call & the crash

[shell]$ python test.py
Traceback (most recent call last):
  File "test.py", line 32, in ?
    result = server.person.update(person)
  File "/ogo/scripts/xmlrpclib.py", line 829, in __call__
    return self.__send(self.__name, args)
  File "/ogo/scripts/xmlrpclib.py", line 992, in __request
    request = dumps(params, methodname, encoding='utf-8')
  File "/ogo/scripts/xmlrpclib.py", line 771, in dumps
    data = m.dumps(params)
  File "/ogo/scripts/xmlrpclib.py", line 458, in dumps
    result = string.join(self.__out, "")
  File "/usr/lib/python2.3/string.py", line 135, in join
    return sep.join(words)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: 
ordinal not in range(128)
[shell]$

#---------------- 'string.join' seems to be innocent:  the following 
script works fine:

#!/usr/bin/env python
# coding: latin-1

import string
from xmlrpclib import *

s0 = 'ascii'
s1 = u'São Paulo'
s2 = u'S\xc3\xa3o Paulo'

a = []
a.append( s0)
a.append( s1)
a.append( s2)

print string.join(a, '|')



-- 
OpenGroupware.org XML-RPC
[email protected]
http://mail.opengroupware.org/mailman/listinfo/xmlrpc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.