Issue #1111 open

AttributeError: 'HeaderElement' object has no attribute 'split'

mischko
created an issue

I get this error:

{{{ Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/usr/local/lib/python2.6/dist-packages/cherrypy/lib/encoding.py", line 204, in call ct = response.headers.elements("Content-Type") File "/usr/local/lib/python2.6/dist-packages/cherrypy/lib/httputil.py", line 436, in elements return header_elements(key, value) File "/usr/local/lib/python2.6/dist-packages/cherrypy/lib/httputil.py", line 216, in header_elements for element in fieldvalue.split(","): AttributeError: 'HeaderElement' object has no attribute 'split' }}}

... when I run this code:

{{{ class FileHandler(): def index(self): return """ <html><body> <form action="/filer/recirc_download" method="post" enctype="multipart/form-data"> File: <input type="file" name="theFile"/> <br/> <input type="submit"/> </form> </body></html> """ index.exposed = True

def recirc_download(self, theFile):
    theData = theFile.read()
    theMimeType = theFile.type
    cherrypy.log("CP Response Headers: %s" % str(cherrypy.response.headers))
    cherrypy.response.headers['Content-Length'] = len(theData)
    cherrypy.log("POINT A")
    cherrypy.response.headers['Content-Type'] = theMimeType
    return theData
recirc_download.exposed = True

}}}

Comments (5)

  1. Jason R. Coombs

    Or use unicode(theFile.type) (Python 2) or str(theFile.type) (Python 3).

    I believe it is a bug, because it's a regression from Python 3.0 but not mentioned in the What's New for 3.1 or 3.2.

  2. Log in to comment