Odoo connexion - UnicodeEncodeError

Hi everyone !

I try to make an Odoo API Call in a new make scenario but I have an issue.
It’s look to be a problem with bad caracter (like “é”) in my database…
Can you help me to resolve this ?

Here the complete error message :
[1] Traceback (most recent call last):
File “/home/odoo/src/odoo/12.0/odoo/api.py”, line 1049, in get
value = self._data[key][field][record._ids[0]]
KeyError: 7138

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/odoo/src/odoo/12.0/odoo/fields.py”, line 1064, in get
value = record.env.cache.get(record, self)
File “/home/odoo/src/odoo/12.0/odoo/api.py”, line 1051, in get
raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: (‘res.partner(7138,).email_formatted’, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/odoo/src/odoo/12.0/odoo/addons/base/controllers/rpc.py”, line 69, in xmlrpc_2
response = self._xmlrpc(service)
File “/home/odoo/src/odoo/12.0/odoo/addons/base/controllers/rpc.py”, line 49, in _xmlrpc
result = dispatch_rpc(service, method, params)
File “/home/odoo/src/odoo/12.0/odoo/http.py”, line 120, in dispatch_rpc
result = dispatch(method, params)
File “/home/odoo/src/odoo/12.0/odoo/service/model.py”, line 40, in dispatch
res = fn(db, uid, *params)
File “/home/odoo/src/odoo/12.0/odoo/service/model.py”, line 178, in execute_kw
return execute(db, uid, obj, method, *args, **kw or {})
File “/home/odoo/src/odoo/12.0/odoo/service/model.py”, line 98, in wrapper
return f(dbname, *args, **kwargs)
File “/home/odoo/src/odoo/12.0/odoo/service/model.py”, line 185, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File “/home/odoo/src/odoo/12.0/odoo/service/model.py”, line 169, in execute_cr
result = odoo.api.call_kw(recs, method, args, kw)
File “/home/odoo/src/odoo/12.0/odoo/api.py”, line 755, in call_kw
return _call_kw_model(method, model, args, kwargs)
File “/home/odoo/src/odoo/12.0/odoo/api.py”, line 728, in _call_kw_model
result = method(recs, *args, **kwargs)
File “/home/odoo/src/odoo/12.0/odoo/models.py”, line 4634, in search_read
result = records.read(fields)
File “/home/odoo/src/odoo/12.0/odoo/models.py”, line 2837, in read
vals[name] = convert(record[name], record, use_name_get)
File “/home/odoo/src/odoo/12.0/odoo/models.py”, line 5169, in getitem
return self._fields[key].get(self, type(self))
File “/home/odoo/src/odoo/12.0/odoo/fields.py”, line 1068, in get
self.determine_value(record)
File “/home/odoo/src/odoo/12.0/odoo/fields.py”, line 1181, in determine_value
self.compute_value(recs)
File “/home/odoo/src/odoo/12.0/odoo/fields.py”, line 1135, in compute_value
self._compute_value(records)
File “/home/odoo/src/odoo/12.0/odoo/fields.py”, line 1126, in _compute_value
getattr(records, self.compute)()
File “/home/odoo/src/odoo/12.0/odoo/addons/base/models/res_partner.py”, line 401, in _compute_email_formatted
partner.email_formatted = tools.formataddr((partner.name or u"False", partner.email or u"False"))
File “/home/odoo/src/odoo/12.0/odoo/tools/mail.py”, line 593, in formataddr
address.encode(‘ascii’)
UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\xe9’ in position 1: ordinal not in range(128)

Hey @gfilali,

If bad characters are indeed causing the problem, you might want to try the ascii() function. This can remove any non-ascii characters and even replace them with the closest ascii character.
CleanShot 2022-07-15 at 09.40.45

Similar problems sometimes occur when text is encoded in the wrong format. For this, you may want to look at the ‘Convert the encoding of a text’ action. UTF-8 is probably the most common type of encoding.
CleanShot 2022-07-15 at 09.42.11

Hope this was useful!

1 Like