Issue #1194 resolved

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

created an issue

When the url contains Chinese, like "你", an error occurs.

Error: 404, "The path '/ä½\xa0' was not found."

I added 2 lines on cherrypy/ line 310, then it works ok. I do not know why.

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.
                    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.
                    # Only set transcoded values if they both succeed.
                    path = u_path
                    qs = u_qs

Comments (2)

  1. Joel Rivera

    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

    → <<cset cb9261b32601>>

  2. Log in to comment