Skip to content
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

wsgiref's wsgi application sample code does not work #56177

Closed
shimizukawa mannequin opened this issue May 1, 2011 · 6 comments
Closed

wsgiref's wsgi application sample code does not work #56177

shimizukawa mannequin opened this issue May 1, 2011 · 6 comments
Labels
docs Documentation in the Doc dir

Comments

@shimizukawa
Copy link
Mannequin

shimizukawa mannequin commented May 1, 2011

BPO 11968
Nosy @terryjreedy, @pjeby, @merwok, @bitdancer, @skrah, @shimizukawa

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-05-11.14:29:20.938>
created_at = <Date 2011-05-01.05:56:22.530>
labels = ['docs']
title = "wsgiref's wsgi application sample code does not work"
updated_at = <Date 2011-05-11.14:38:04.419>
user = 'https://github.com/shimizukawa'

bugs.python.org fields:

activity = <Date 2011-05-11.14:38:04.419>
actor = 'python-dev'
assignee = 'docs@python'
closed = True
closed_date = <Date 2011-05-11.14:29:20.938>
closer = 'orsenthil'
components = ['Documentation']
creation = <Date 2011-05-01.05:56:22.530>
creator = 'shimizukawa'
dependencies = []
files = []
hgrepos = []
issue_num = 11968
keywords = []
message_count = 6.0
messages = ['134900', '135325', '135387', '135486', '135780', '135781']
nosy_count = 8.0
nosy_names = ['terry.reedy', 'pje', 'eric.araujo', 'r.david.murray', 'skrah', 'docs@python', 'shimizukawa', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue11968'
versions = ['Python 3.2', 'Python 3.3']

@shimizukawa
Copy link
Mannequin Author

shimizukawa mannequin commented May 1, 2011

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')]

@shimizukawa shimizukawa mannequin assigned docspython May 1, 2011
@shimizukawa shimizukawa mannequin added the docs Documentation in the Doc dir label May 1, 2011
@merwok
Copy link
Member

merwok commented May 6, 2011

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?

@terryjreedy
Copy link
Member

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:\DOCUME~1\Terry\LOCALS~1\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?

@pjeby
Copy link
Mannequin

pjeby mannequin commented May 7, 2011

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.

@python-dev
Copy link
Mannequin

python-dev mannequin commented May 11, 2011

New changeset e7c62e0981c7 by Senthil Kumaran in branch 'default':
Fix closed Issue bpo-11968 - the start_response header values in wsgiref shoudl be
http://hg.python.org/cpython/rev/e7c62e0981c7

@python-dev
Copy link
Mannequin

python-dev mannequin commented May 11, 2011

New changeset 5add0c01933f by Senthil Kumaran in branch '3.2':
Issue bpo-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 bpo-11968 - the start_response header values in wsgiref shoudl be
http://hg.python.org/cpython/rev/482f60d6a687

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants