-
-
Notifications
You must be signed in to change notification settings - Fork 368
Closed
Description
Originally reported by: ywzhaiqi (Bitbucket: ywzhaiqi, GitHub: ywzhaiqi)
When the url contains Chinese, like "你", an error occurs.
Error:
404, "The path '/ä½\xa0' was not found."
I added 2 lines on cherrypy/_cpwsgi.py line 310, then it works ok.
I do not know why.
#!python
if py3k:
# This isn't perfect; if the given PATH_INFO is in the wrong encoding,
# it may fail to match the appropriate config section URI. But meh.
old_enc = self.environ.get('wsgi.url_encoding', 'ISO-8859-1')
new_enc = self.cpapp.find_config(self.environ.get('PATH_INFO', ''),
"request.uri_encoding", 'utf-8')
if new_enc.lower() != old_enc.lower():
# Even though the path and qs are unicode, the WSGI server is
# required by PEP 3333 to coerce them to ISO-8859-1 masquerading
# as unicode. So we have to encode back to bytes and then decode
# again using the "correct" encoding.
try:
u_path = path.encode(old_enc).decode(new_enc)
u_qs = qs.encode(old_enc).decode(new_enc)
# two lines added by me
u_path = u_path.encode(old_enc).decode(new_enc)
u_qs = u_qs.encode(old_enc).decode(new_enc)
except (UnicodeEncodeError, UnicodeDecodeError):
# Just pass them through without transcoding and hope.
pass
else:
# Only set transcoded values if they both succeed.
path = u_path
qs = u_qs
Reactions are currently unavailable