1. cherrypy
  2. CherryPy
Issue #867 resolved

tools.decode fails with 'Content-Type','application/xml' in headers

guest
created an issue

Our application had the following config dictionary: {{{ dConfXml={ '/':{ 'tools.decode.on':True, 'tools.decode.default_encoding':'utf-8', 'tools.response_headers.on':True, 'tools.response_headers.headers':[ ('Cache-Control','no-cache, no-store, private, max-age=0'), ('Pragma','no-cache'), ('Content-Type','application/xml') ], 'tools.encode.on':True, 'tools.encode.encoding':'utf-8', 'tools.encode.errors':'replace', 'tools.gzip.on':True, 'tools.gzip.mime_types':['application/xml'] } } cherrypy.tree.mount(MyXmlClass(),'/myxmlclass',config=dConfXml) }}} This produces the following traceback: {{{ [27/Oct/2008:12:43:20] HTTP Request Headers: ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 PRAGMA: no-cache Content-Type: application/x-www-form-urlencoded; charset=utf-8 REFERER: http://192.168.0.11:8080/ HOST: 192.168.0.11:8080 CACHE-CONTROL: no-cache Content-Length: 77 ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7 USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 CONNECTION: keep-alive Remote-Addr: 192.168.0.11 ACCEPT-ENCODING: gzip,deflate KEEP-ALIVE: 300 [27/Oct/2008:12:43:20] HTTP Traceback (most recent call last): File "C:\Program Files\Python\2.4\Lib\site-packages\cherrypy_cprequest.py", line 610, in respond cherrypy.response.finalize() File "C:\Program Files\Python\2.4\Lib\site-packages\cherrypy_cprequest.py", line 881, in finalize content = self.collapse_body() File "C:\Program Files\Python\2.4\Lib\site-packages\cherrypy_cprequest.py", line 854, in collapse_body newbody = ''.join([chunk for chunk in self.body]) File "C:\Program Files\Python\2.4\Lib\site-packages\cherrypy\lib\encoding.py", line 193, in compress crc = zlib.crc32(line, crc) UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 15: ordinal not in range(128)

192.168.0.11 - - [27/Oct/2008:12:43:20] "POST /myxmlclass/ HTTP/1.1" 500 1511 "http://192.168.0.11:8080/" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" }}} Changing content/mime type from 'application/xml' to 'text/xml' makes it work as expected.

This is a minor problem but the solution is not obvious.

Comments (2)

  1. Log in to comment