1

I got the following error in a live site where a utf character (test string 'Îñţérñâţîöñåļîžæ†îøñ') was submitted:

400 Bad Request

The request entity could not be decoded. The following charsets were attempted: ['utf-8']

Traceback (most recent call last):
  File ".virtual/local/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 648, in respond
    self.body.process()
  File ".virtual/local/lib/python2.7/site-packages/cherrypy/_cpreqbody.py", line 931, in process
    super(RequestBody, self).process()
  File ".virtual/local/lib/python2.7/site-packages/cherrypy/_cpreqbody.py", line 500, in process
    proc(self)
  File ".virtual/local/lib/python2.7/site-packages/cherrypy/_cpreqbody.py", line 153, in process_urlencoded
    "charsets were attempted: %s" % repr(entity.attempt_charsets))
HTTPError: (400, "The request entity could not be decoded. The following charsets were attempted: ['utf-8']")
Powered by CherryPy 3.2.0

I can fix this using <form type="POST" accept-charset="utf-16">.

Normally, I catch errors in application code and log them or email them to myself, but this error never reached my application code which runs on TurboGears 1.5.

Any idea on how I can hook in to catch and log errors generated by CherryPy, and secondarily, give the user a better 404 page?


The method of error handling listed at _cperror.html#unanticipated-errors doesn't work for this sort of error (but kicks in on e.g. static file missing)

EoghanM
  • 20,021
  • 21
  • 80
  • 110
  • 1
    I've added a pull request: https://bitbucket.org/cherrypy/cherrypy/pull-request/93/add-error-handling-hook-to-http-400 – EoghanM Feb 23 '15 at 00:08

0 Answers0