'ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)

226 views
Skip to first unread message

Gael Princivalle

unread,
Jan 6, 2017, 11:27:17 AM1/6/17
to web2py-users
Hello.

I'm made a new application in a new web2py installation 2.14.6. The db is PostGis.
It's a mountain bike meeting platform.
There's only one user for the moment, myself ☺.

Here is an event:

You can see that the event description is:
Per chi si vuole unire. Andrò a fare un giretto per le scale del Valentino, e poi qualche su e giu nel parco Leopardi, lavorando su aspetti tecnici.

When I display it in the mtb_ride page no problem:
{{=DIV(event.description, _class='trail_description', _id='trail_description')}}

If I try in the controller to concatenate event.description with event.title:
description = title + ' ' + event.description

I've a ticket, due to the 'ò'. Here is the traceback:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Traceback (most recent call last):
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/mtbconnection/controllers/default.py", line 392, in <module>
File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/globals.py", line 417, in <lambda>
self._caller = lambda f: f()
File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/mtbconnection/controllers/default.py", line 249, in mtb_ride
description = title + ' ' + event.description
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)

I've seen that someone have got a similar problem and resolved it installing psycopg2.
I've installed it:
pip install psycopg2
I've restarted the server.

Problem still the same.

Can someone give me a hand?

Thanks, regards.







Gael Princivalle

unread,
Jan 6, 2017, 11:46:29 AM1/6/17
to web2py-users
PostGis is in utf8.

I've tried to force the utf8 codification like that:
    description = title + ' ' + event.description.encode("utf-8")

Same error.

Leonel Câmara

unread,
Jan 6, 2017, 12:08:13 PM1/6/17
to web...@googlegroups.com
Is it possible the python file itself where your controller is, is not in utf-8?

Gael Princivalle

unread,
Jan 6, 2017, 1:23:16 PM1/6/17
to web2py-users
I edit the controller with notepad ++. Format is UTF-8 without BOM.
I've also tried to save it with the web2py amministrative interface, same error.

Gael Princivalle

unread,
Jan 7, 2017, 3:12:19 AM1/7/17
to web2py-users
I've tried also like that:
description = title + 'ò'
Same error.

description = '%s %s' %(title, event.description)
Same error.

description = 'ò'

No error.

Gael Princivalle

unread,
Jan 7, 2017, 6:05:20 AM1/7/17
to web2py-users
Ok I've found the problem.
In the title I've hadded before a date with a different encode. Thanks Leonel for the help.
Reply all
Reply to author
Forward
0 new messages