Pergunta

I started getting this error when I try to select one field. It is weird, because it does not give this error for any other field in that class. I don't understand why it even uses 'ascii' codec here, when for others it does not. If I change label to consist only from ascii symbols, then error disappears, but that is not a solution.

my field is described like this:

    'partner_p_id':fields.many2one('res.partner','PASPĮ', domain=[('is_paspi','=',True)], track_visibility='onchange'),

It is tracked in _track:

_track = {
  'partner_p_id':{},
}

Encoding used in file:

# -*- encoding: utf-8 -*-

Exact error looks like this:

File "/openerp/server/openerp/addons/mail/mail_thread.py", line 366, in format_message
    message += '%s</div>' % change.get('new_value')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 34: ordinal not in range(128)
2014-03-06 13:21:14,042 13455 ERROR amb_test openerp.netsvc: ascii
<div> &nbsp; &nbsp; &bull; <b>PASPĮ</b>: 
34
35
ordinal not in range(128)

As I said my other fields are tracked the same and some have non ascii symbols in labels too, but it does not give such error for any other field.

Foi útil?

Solução

You're mixing strings and unicodes. Given the error message I guess that this is what happens:

>>> message = u''
>>> message += '%s</div>' % ('<div> &nbsp; &nbsp; &bull; <b>PASPĮ</b>:')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 34: ordinal not in range(128)

You can deal with it by making sure that in the change.get('new_value') call a unicode string is returned. You can do either this (notice the u sign before the string in parentheses):

message += '%s</div>' % (u'<div> &nbsp; &nbsp; &bull; <b>PASPĮ</b>:')

or this (notice the .decode('utf-8'):

message += '%s</div>' % ('<div> &nbsp; &nbsp; &bull; <b>PASPĮ</b>:'.decode('utf-8'))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top