New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python3.2] [CherryPy 3.2.2] encoding of the request path error on Windows 7 #1194

Closed
bb-migration opened this Issue Dec 21, 2012 · 2 comments

Comments

Projects
None yet
1 participant
@bb-migration

bb-migration commented Dec 21, 2012

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


@bb-migration

This comment has been minimized.

Show comment
Hide comment
@bb-migration

bb-migration Jul 14, 2013

Original comment by Joel Rivera (Bitbucket: cyraxjoe, GitHub: cyraxjoe):


Issue #1248 was marked as a duplicate of this issue.

bb-migration commented Jul 14, 2013

Original comment by Joel Rivera (Bitbucket: cyraxjoe, GitHub: cyraxjoe):


Issue #1248 was marked as a duplicate of this issue.

@bb-migration

This comment has been minimized.

Show comment
Hide comment
@bb-migration

bb-migration Jul 14, 2013

Original comment by Joel Rivera (Bitbucket: cyraxjoe, GitHub: cyraxjoe):


Bugfix, there was a double encoding for the PATH_INFO of the wsgienv,
this was causing an error when uri was using something different than
ISO-8859-1 and wasn't able to find the appropiate method to call
in python3 resulting in a 404.

Closing issue #1194

bb-migration commented Jul 14, 2013

Original comment by Joel Rivera (Bitbucket: cyraxjoe, GitHub: cyraxjoe):


Bugfix, there was a double encoding for the PATH_INFO of the wsgienv,
this was causing an error when uri was using something different than
ISO-8859-1 and wasn't able to find the appropiate method to call
in python3 resulting in a 404.

Closing issue #1194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment