-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WSGI applications are required to return bytes. #2
Comments
Hello Graham, Thanks for your investigations. Howerer, WSGIserver is a fork of CherryPy's WSGI Server which is widely used in production. |
That doesn't excuse the fact that it is not compliant with the WSGI specification if it is converting Unicode strings in response byte to bytes. Someone could write code that works on this WSGI server and will then blow up when used on other WSGI compliant WSGI servers. The point of the WSGI specification is to ensure portability for peoples WSGI applications. |
It's undefined, so this could be either an error or something else. It seems compliant. |
Earlier in PEP 3333 it says:
So it MUST yield byte strings. Then in Unicode issues section it says:
So in neither Python 2 or 3 is it allowed to be Unicode string, which would be unicode type under Python 2 and str under Python 3. |
Yes the application MUST, and is faulty not to do so, but it's unrelated to the server behaviour. In this case, the server behaviour is undefined, so it can do what it wants and be compliant. |
It is a poor server implementation that doesn't hold WSGI applications to the WSGI specification and tell them when they are violating it. It is a disservice to users to not tell them there is a problem and silently allow it as it will only come back and bite them later. For example, you are converting using Latin-1. So it will work if only ASCII characters were used in the Unicode string, so hello world will work, but would then blow up if required UTF-8. A user could go along blissfully unaware until their production application starts failing in ways they don't understand. |
@GrahamDumpleton if you see something else you're welcome :-) |
If you are going to add a check, it should be |
it's already here 7352501 ! |
Tell me what is going to happen if someone incorrectly does:
You are checking whether the items are text type (presumably that maps to unicode on Python 2 and str on Python 3) and only raise an exception in that very specific case. There are still lots of other types besides bytes which someone could accidentally return and that check will not catch them and will pass it straight through. That is why the exception should be for anything which IS NOT bytes. |
Correct. Fixed. Thanks a lot @GrahamDumpleton |
This code looks suspect:
A WSGI application iterable is supposed to return byte strings for response body. If it returns Unicode strings it is an error.
A WSGI server is not meant to convert Unicode strings to byte strings automatically.
Thus concerned about what the code:
is doing.
The text was updated successfully, but these errors were encountered: