Issue #943 resolved

cherrypy's wsgi support not to spec for Python 3.x

Anonymous created an issue

As is described on - in Python 3.x the http status provided to start_response must be a (unicode) string, not a byte string. Currently with Python 3.1 and CherryPy 3.2.0 the following error is raised when used with mod_wsgi:

TypeError: start_response() argument 1 must be string, not bytes

Using s.decode('utf-8') as the first argument to start_response seems to fix the problem, though this may not be the best solution.

Reported by

Comments (4)

  1. Anonymous

    Actually, neither the proposed ammendments or the discussion about them has explicitly said what 'status' value passed as first argument to start_response() should be. If one were to follow what was being done with the headers, then bytes should perhaps be accepted, with WSGI server converting any unicode string to bytes per latin-1 encoding otherwise. Thus, mod_wsgi is perhaps doing the wrong thing, but only because fixing up that code for Python 3.0 was overlooked. :-)

    BTW, do note that irrespective of the fact that there are proposed ammendments, there is no WSGI specification for Python 3.0 and so although producers of WSGI servers may try and implement what they think is reasonable, it may not actually match what the WSGI specification for Python 3.0, if one is ever produced, may say.

    For that reason, for mod_wsgi at least there is a huge disclaimer in documentation which says:

    """All ability to use Python 3.0 with mod_wsgi is not supported. If you have a problem with mod_wsgi and what it does, first go get the Python WEB-SIG people to agree on what it should do first."""

    So be warned, if you are trying to write WSGI applications for Python 3.0, then don't necessarily expect that it will work with any WSGI specification for Python 3.0 if one is produced. Also don't complain to the authors of the WSGI servers if it doesn't do what you expect, go petition the Python WEB-SIG or even Guido himself to sort this mess out and come out with an official WSGI specification update for Python 3.0. Personally, I have given up trying any more and will not be doing any more development work around Python 3.0 for mod_wsgi until there is a specification, although I will fix up at least how 'status' is treated as it doesn't match how other bits of mod_wsgi currently work with Python 3.0.

  2. Anonymous

    Revision 1389 of mod_wsgi subversion repository trunk now accepts bytes for status string and will convert unicode per latin-1 encoding.

    This issue for CherryPy can likely now be closed since arguably not a problem with CherryPy, although lack of WSGI specification to say exactly what should be returned is still an issue.

  3. Log in to comment