This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: WSGI examples raise AttributeError: __exit__
Type: Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Nils-Hero, r.david.murray
Priority: normal Keywords:

Created on 2017-06-06 12:34 by Nils-Hero, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (10)
msg295253 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 12:34
All examples on

https://docs.python.org/3/library/wsgiref.html

raise this exception:

Traceback (most recent call last):
  File "C:\Code\test\server.py", line 110, in <module>
    with make_server('', 8000, simple_app) as httpd:
AttributeError: __exit__

Tested with

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
msg295256 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-06 12:54
something is wrong in your setup then.  I suspect you have a mismatch between the python version you think you are running the one you are actually running, and/or which library code it is accessing.
msg295257 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-06 12:55
Either that or you aren't really running the make_server from wsgiref.simple_server.
msg295289 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 18:29
I tried a few online python 3 interpreters.

These give the same exception:

http://www.learnpython.org/en/Hello%2C_World%21
http://rextester.com/l/python3_online_compiler
http://ideone.com/pIMilt
http://www.tutorialspoint.com/execute_python3_online.php

And this one worked:

https://repl.it/languages/python3

the example i tried was:

from wsgiref.simple_server import make_server, demo_app
with make_server('', 8000, demo_app) as httpd:
    print("Serving HTTP on port 8000...")
    httpd.serve_forever()

My Python installation is a default x64 installation. No changes were made during installation, except installation path, which has no spaces in it. I have no third part modules installed which could interfer. I have also a Python 2.7 installed but it is not on my path.
msg295290 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 18:31
I just found out that the example works in idle and if i do in a console:

python server.py

but not if i do just:

server.py

What is the secret behind this?
msg295291 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-06 18:42
If you just type 'server.py' it will use whichever interpreter is associated with .py files, which might not be python3.  You may want to learn about the 'py' helper command.
msg295292 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 18:49
What would that be? If i google 'py helper command' i get no good results.
msg295293 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-06 19:08
It gets installed along with python3, I believe.  If you google for 'python py' you should see the pypi package version in the top hits.
msg295308 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 22:43
I am not sure if the py package i found on PyPi is what you meant, but if you mean the py launcher (the py.exe in the windows dir), yes, i have that.

My system was indeed misconfigured as you correctly guessed, i had the .py filetype pointing to a Python version 3.5. I have now uninstalled everything, manually cleaned up the registry, reinstalled Python 3.6 and now everything works. Sorry, my mistake.
msg295309 - (view) Author: Nils Lindemann (Nils-Hero) * Date: 2017-06-06 22:45
ok
History
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74765
2017-06-07 15:31:06r.david.murraysetresolution: not a bug
2017-06-06 22:45:18Nils-Herosetstatus: open -> closed

messages: + msg295309
2017-06-06 22:43:36Nils-Herosetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg295308
2017-06-06 19:08:28r.david.murraysetstatus: open -> closed
resolution: not a bug
messages: + msg295293
2017-06-06 18:49:17Nils-Herosetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg295292
2017-06-06 18:42:41r.david.murraysetstatus: open -> closed
resolution: not a bug
messages: + msg295291

stage: resolved
2017-06-06 18:31:02Nils-Herosetmessages: + msg295290
2017-06-06 18:29:26Nils-Herosetmessages: + msg295289
2017-06-06 12:55:54r.david.murraysetmessages: + msg295257
2017-06-06 12:54:52r.david.murraysetnosy: + r.david.murray
messages: + msg295256
2017-06-06 12:34:54Nils-Herocreate