unicode parameters encoding which should be used with .url() calls ?

16 views
Skip to first unread message

matkor

unread,
Nov 22, 2011, 6:57:42 AM11/22/11
to Pesto
Assuming foo being decoreted
@dispatcher.match('/foo/<bar:unicode>', 'GET')
and later bar being utf-8 encoded string I get:

foo.url(bar=bar)
File "/usr/share/python2.7/site-packages/pesto/dispatch.py", line
852, in url
File "/usr/share/python2.7/site-packages/pesto/dispatch.py", line
372, in pathfor
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
14: ordinal not in range(128)

Switching to
foo.url(bar=bar.decode('utf-8')
works.

Is there way to specify encoding which should be used with .url()
calls ?
Seems now pesto tries to use ascii to decode.

TIA, regards, python-pesto-21

Oliver Cope

unread,
Nov 22, 2011, 9:24:10 AM11/22/11
to python...@googlegroups.com

On 22/11/2011 12:57, matkor wrote:
> Assuming foo being decoreted
> @dispatcher.match('/foo/<bar:unicode>', 'GET')
> and later bar being utf-8 encoded string I get:
>
> foo.url(bar=bar)
> File "/usr/share/python2.7/site-packages/pesto/dispatch.py", line
> 852, in url
> File "/usr/share/python2.7/site-packages/pesto/dispatch.py", line
> 372, in pathfor
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 14: ordinal not in range(128)
>

I think it is using the system encoding, which is usually ascii. You can
change this, but it's awkward to do and I've never found it necessary.

> Switching to
> foo.url(bar=bar.decode('utf-8')
> works.
>

While this will work, I suggest you use unicode strings throughout your
code wherever possible, so that 'bar' is decoded into unicode string
from the moment it enters your application. That usually helps avoid
this kind of error.

Olly.

Reply all
Reply to author
Forward
0 new messages