Why exception from os.path.exists()?

Chris Angelico rosuav at gmail.com
Sun Jun 10 05:22:14 EDT 2018


On Sun, Jun 10, 2018 at 7:06 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>> It's important to pin down the true cause of the problem, and not
>> blame something for doing the proper Pythonic thing.
>
> So could you tell me what the proper Pythonic fix for the example server
> in Python's documentation would be?
>
> Here's the code in question:
>
> ========================================================================
> import http.server
> import socketserver
>
> PORT = 8000
>
> Handler = http.server.SimpleHTTPRequestHandler
>
> with socketserver.TCPServer(("", PORT), Handler) as httpd:
>     print("serving at port", PORT)
>     httpd.serve_forever()
> ========================================================================
>
> BTW, the proper response would be a 404. 500 means: "There's a bug in my
> code".
>

The fix is a pull request against serve_forever to catch exceptions
and return 500s.

ChrisA



More information about the Python-list mailing list