I just came across this problem.
Suppose I have this (minimal) controller:
class Root(controllers.RootController):
@expose()
def test(self, *args, **kwargs):
return "bla"
@expose()
@identity.require(identity.not_anonymous())
def test2(self, *args, **kwargs):
return "bla2"
When I call `/test?a=ä`, all works as expected. But when I call the
second handler `/test2?a=ä`, I get an error:
500 Internal error
The server encountered an unexpected condition which prevented it from
fulfilling the request.
Page handler: 'ordinal not in range(128)'
Traceback (most recent call last):
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\_cphttptools.py", line 103, in _run
applyFilters('before_main')
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\__init__.py", line 151, in applyFilters
method()
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 31, in before_main
self.decode(enc)
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 50, in decode
decodedParams[key] = value.decode(enc)
File "c:\programme\python25\lib\encodings\utf_8.py", line 16, in
decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 0: ordinal not in range(128)
I guess that this is not supposed to throw this error, is it?
I'm using TG 1.0.4b2.
Thanks for any advice!
Good catch!
Could you create a ticket on our trac system and ping us back here.
Please try to attach some example project so we can reproduce easily
the error.
Thanks,
Florent.
> Could you create a ticket on our trac system and ping us back here.
Great, my ticket got rejected: "Submission rejected as potential spam
(Akismet says content is spam)"
Text:
==== 8< ====
Suppose I have this (minimal) controller:
{{{
class Root(controllers.RootController):
@expose()
def test(self, *args, **kwargs):
return "bla"
@expose()
@identity.require(identity.not_anonymous())
def test2(self, *args, **kwargs):
return "bla2"
}}}
When I call `/test?a=ä`, all works as expected.
But when I call the second handler `/test2?a=ä`, I get an error:
{{{
500 Internal error
[..]
File "[..]python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg
\cherrypy\filters\decodingfilter.py", line 50, in decode
decodedParams[key] = value.decode(enc)
File "[..]python25\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 0: ordinal not in range(128)
}}}
The full test project (actually, only the controllers.py has been
modified after the quickstart) is attached.
==== >8 ====
> Please try to attach some example project so we can reproduce easily
> the error.
Can be downloaded here: http://gedankenkonstrukt.de/files/tg-id-utf-bug.zip
Cheers
Found another, maybe related bug:
`/test2?a.b=b`
500 Internal error
The server encountered an unexpected condition which prevented it from
fulfilling the request.
Traceback (most recent call last):
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\_cphttptools.py", line 103, in _run
applyFilters('before_main')
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\__init__.py", line 151, in applyFilters
method()
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 31, in before_main
self.decode(enc)
File "c:\programme\python25\lib\site-packages\cherrypy-2.2.1-
py2.5.egg\cherrypy\filters\decodingfilter.py", line 50, in decode
decodedParams[key] = value.decode(enc)
AttributeError: 'dict' object has no attribute 'decode'
Seems like Identity and CP are battling each other in decoding the
request params...
We just created the spam filtering but now we trained it a little and
also tweaked the parameters, so it should accept you ticket. Could you
try again to create it ? And sorry for the inconvenience.
Florent.
Ok, works.
Filed as #1598 under http://trac.turbogears.org/ticket/1598