Odoo Help

0

User and unicode character error.

By
Ricardo Balcácer
on 7/24/13, 10:50 PM 6,851 views

There is a problem creating a user with a character that is not in the 7-bit ASCII list inside the login field. For example accented characters in spanish produce the problem. You can create the user the problem arises once you try to access the form of the user again, the following error appears :

...

File "/usr/lib/python2.6/site-packages/openerp-7.0_20130716_231027-py2.6.egg/openerp/addons/auth_signup/res_users.py", line 87, in _get_signup_url_for_action res[partner.id] = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment))) File "/usr/lib/python2.6/urllib.py", line 1269, in urlencode v = quote_plus(str(v)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xa1' in position 0: ordinal not in range(128)

This is a common problem for python. Anyways it's better if you avoid non utf-8 characters.

GH Mediacloud, Grover Menacho
on 7/25/13, 12:07 AM
2
passat
On 8/15/14, 8:08 AM

Find  in  addons/auth_signup/res_users.py a string 

                fragment['login'] = partner.user_ids[0].login 

and replace it with
                fragment['login'] = partner.user_ids[0].login.encode('utf-8')

 

 

That's what I do in some cases with translated strings.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/9/15, 5:40 AM
1
Andres Brigard
On 3/7/16, 2:08 PM

I changed the openerp-server file and inserted these lines in the third line:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')


Thanks Andres. It worked.

Giezel Esteves
on 1/14/17, 3:43 AM
1
Nishant Kashyap
On 7/25/13, 4:08 AM

Once I got struck on the same error, When I was write a data into the excel file using xlrd python module. you can ignore the string encoded in ascii example:

str = u'\xa56'
print str.encode('ascii')  # If this fails then use next line to ignore
str.encode('ascii','ignore')

You will get the empty string .

But If you still want to use the string value then django smart_str will work.

in Django1.5 smart_text is used. Copy this .py code and put this in your module link text

Then :

from django.utils.encoding import smart_text, smart_unicode,smart_str

smart_text(str)
smart_str(str)
smart_unicode(str)

If you did not able to import the above module then download django zip code link text

get into its directory install django using :

python setup.py install

then open python in shell then use

from django.utils.encoding import smart_text, smart_unicode,smart_str

Good point, thank you. I actually tried to use your same solution but with str.encode('utf8') works great quite alright what should be expected. I believe that the error is ocurring because the value of the string is being passed throught the 'str()', not sure if the login is intended to have only 7-bit ascii characters and if so the system shouldn't let you write those characters in the first place or if so then the functions selected should be able to handle UTF-8 out of the box. I already opened a bug in launchpad hope it raises concern. It seems like a simple error that a validation solves

Ricardo Balcácer
on 7/25/13, 10:11 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 7/24/13, 10:50 PM
Seen: 6851 times
Last updated: 3/7/16, 2:08 PM