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
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.