Issue #1303 new

error_page.404 utf-8 handling error

Anonymous created an issue

Hi, i have russian chars encoded with utf-8 in 404.html

When referring to a nonexistent page get an "500 Internal Server Error"

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last):
  File "C:\Work\Internet\library\python\lib\site-packages\cherrypy\_cprequest.py", line 664, in respond
    inst.set_response()
  File "C:\Work\Internet\library\python\lib\site-packages\cherrypy\_cperror.py", line 376, in set_response
    message=self._message).encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 149: ordinal not in range(128)
Powered by CherryPy 3.2.5

Config:

cherrypy.config.update({
        'global': {
             ...
            'error_page.404': r'%s/public/internet/errors/404.html' % WORKING_DIRECTORY
        }
    })

Comments (7)

  1. Sviatoslav Sydorenko

    Hi,

    I found a workaround for this (I may prepare a pull-request once tested under python2). All works if you replace encoding in wsgiserver/wsgiserver3.py to utf-8 as follows:

    sed -i 's/ISO-8859-1/UTF-8/g' wsgiserver/wsgiserver3.py
    

    BTW, why don't you use default urllib.parse.unquote here? https://bitbucket.org/cherrypy/cherrypy/src/080abbbd67bae909fc221ee03ecbe86c6c53b257/cherrypy/wsgiserver/wsgiserver3.py?at=default#cl-672

    P.S. I'm running python 3.3 and issue exists in 3.2.4 and 3.2.5. I've mentioned it while using staticdir and requesting url like http://hostname/uploads/gallery/photo/clients/%D1%81%D0%B2%D0%B5%D1%82%D0%BB%D0%BE%D1%84%D0%BEp.png, the filename should be decoded to светлофоp, but in fact it isn't.

  2. Log in to comment