Issue 11968: wsgiref's wsgi application sample code does not work (original) (raw)
Created on 2011-05-01 05:56 by shimizukawa, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (6)
Author: Takayuki SHIMIZUKAWA (shimizukawa)
Date: 2011-05-01 05:56
WSGI sapmle code at wsgiref document (http://docs.python.org/py3k/library/wsgiref.html#wsgiref.util.setup_testing_defaults) was broken.
- status = b'200 OK'
- headers = [(b'Content-type', b'text/plain; charset=utf-8')]
- status = '200 OK'
- headers = [('Content-type', 'text/plain; charset=utf-8')]
Author: Éric Araujo (eric.araujo) *
Date: 2011-05-06 16:53
Thanks for the report. Can you tell more about the bug you perceive? The doc and code for wsgiref were carefully updated to play well with Python 3 clean bytes/characters distinction, so I’m surprised by this bug report. Maybe you mistakenly tried the example with a Python 2.x version?
Author: Terry J. Reedy (terry.reedy) *
Date: 2011-05-06 23:46
Takayuki is correct, the status and header strings should, it seems, be 'native strings', not bytes.
The experimental proof is to run the current example code (I did so from IDLE editor window on WinXP) and then enter http://localhost:8000/
in a browser. Several error messages appear back in the shell window, like
AssertionError: Header names/values must be of type str (got b'Content-type')
Hit ^C to stop. Delete the b prefixes from the code. Rerun. Reaccess.
And the environment dict appears as promised:
TMP: C:\DOCUME1\Terry\LOCALS1\Temp
WATCOM: C:\temp\WatconPermanent
COMPUTERNAME: HP-PAVILION
wsgi.multiprocess: False
...
Takayuki, if you did the same thing, it would have been helpful if you had said so.
Neither version works in 3.1.3. No exception messages either. Firefox says unable to connect. I retried with 3.2.0 and patched example and it worked again.
Running this down in the docs was harder. In the example, function simple_app is a WSGI application object. The status and header objects are passed to the start_response function passed to simple_app after simple_app is passed to make_server. The manual (elsewhere) refers to PEP 3333 for the definition of WSGI app object. The 'start_response Callable' section says the status passed to start_response should be a string and that headers should be a list of tuples of header key and value, but it does not specify the type of the latter. The earlier 'Note on String Types says that headers are, for convenience, native-to-the-version strings while bodies are bytes. So the revised example that works matches the doc.
Phillip or David, can you verify that this is all as intended?
Author: PJ Eby (pje) *
Date: 2011-05-07 17:22
Yes, the 'b' is a docs error.
I previously removed this in:
http://hg.python.org/cpython-fullhistory/rev/2697326d4a77
It appears to have been reverted during a merge, here:
http://hg.python.org/cpython-fullhistory/rev/88d04f0143c7
My browser crashed trying to view that huge second revision, so I'm not sure if there were any other regressions therein.
Author: Roundup Robot (python-dev)
Date: 2011-05-11 14:27
New changeset e7c62e0981c7 by Senthil Kumaran in branch 'default': Fix closed Issue #11968 - the start_response header values in wsgiref shoudl be http://hg.python.org/cpython/rev/e7c62e0981c7
Author: Roundup Robot (python-dev)
Date: 2011-05-11 14:38
New changeset 5add0c01933f by Senthil Kumaran in branch '3.2': Issue #11968 - the start_response header values in wsgiref shoudl be str not http://hg.python.org/cpython/rev/5add0c01933f
New changeset 482f60d6a687 by Senthil Kumaran in branch 'default': [Merge Branch] Issue #11968 - the start_response header values in wsgiref shoudl be http://hg.python.org/cpython/rev/482f60d6a687
History
Date
User
Action
Args
2022-04-11 14:57:16
admin
set
github: 56177
2011-05-11 14:38:04
python-dev
set
messages: +
2011-05-11 14:29:20
orsenthil
set
status: open -> closed
resolution: fixed
stage: needs patch -> resolved
2011-05-11 14:27:39
python-dev
set
nosy: + python-dev
messages: +
2011-05-09 14:37:30
eric.araujo
set
nosy: + skrah
2011-05-07 17:22:35
pje
set
messages: +
2011-05-06 23:46:56
terry.reedy
set
versions: + Python 3.3
nosy: + terry.reedy, r.david.murray, pje
messages: +
stage: needs patch
2011-05-06 16:53:21
eric.araujo
set
nosy: + eric.araujo
messages: +
2011-05-01 05:56:22
shimizukawa
create