Unicode data

Asked by ruddy32

I'm using UTF-8 data with unicode object. Using XML-RPC call my client application update a partner name. My overwriten Partner object implement new methods. Part of it is updating a Pricelist object name using the new Partner name in the source code below.

name = self.read(cr, uid, item.id, ['name'])['name']
vals = { 'name': name.replace(oldName, newName, 1), }

I get the following error : "'ascii' codec can't encode character u'\xe8' in position 45: ordinal not in range(128)"

I have do many changes without success. My database has been created with UNICODE option.

How can I solve it?

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
ruddy32
Solved:
Last query:
Last reply:
Revision history for this message
ruddy32 (sylvain.bonnemaison) said :
#1

oldName and name are string objects and newName is a unicode object

Revision history for this message
ruddy32 (sylvain.bonnemaison) said :
#2

I don't get this problem while debuging under Windows system using eclipse/pydev.

Revision history for this message
ruddy32 (sylvain.bonnemaison) said :
#3

Even if I change it to:

if type(oldName) != unicode:
 oldName = oldName.decode("utf-8")
name = self.read(cr, uid, item.id, ['name'])['name']
if type(name) != unicode:
 name = name.decode("utf-8")
vals = { 'name': name.replace(oldName, newName, 1), }

Revision history for this message
ruddy32 (sylvain.bonnemaison) said :
#4

I solve it using the following code:
if type(name) != unicode:
 name = unicode(name, 'utf-8')
name = name.encode('utf-8')