Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Set debug=True flag for Flask server #156

Merged
merged 1 commit into from
Aug 30, 2016
Merged

Conversation

msukmanowsky
Copy link
Contributor

@msukmanowsky msukmanowsky commented Aug 27, 2016

From the Flask docs, setting debug=True:

  1. activates the debugger
  2. activates the automatic reloader
  3. enables the debug mode on the Flask application

The automatic reloader is not so important for the purposes of the tutorial, but if users modify the Flask server in anyway and introduce a syntax error for example, debug mode dumps out exceptions to the console instead of swallowing them.

I was working along with the tutorial last night and simply did a copypasta of server.py instead of cloning the repo which resulted in me missing comments.py. When querying the comments endpoint, I got a 500 error, but no useful output in the console:

127.0.0.1 - - [27/Aug/2016 09:05:18] "GET /api/comments HTTP/1.1" 500 -

Meanwhile, if debug mode is enabled, I get a handy Traceback dumped to stdout:

Traceback (most recent call last):
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/path/to/pyenvs/code/learn/react/server.py", line 22, in comments_handler
    with open('comments.json', 'r') as f:
IOError: [Errno 2] No such file or directory: 'comments.json'

Although my specific example is a bit contrived as I doubt many other users copy and paste server.py, debug mode is still handy for local development settings.

@sophiebits
Copy link
Member

Can you explain what practical difference this makes for the purposes of this tutorial?

@msukmanowsky
Copy link
Contributor Author

Apologies, meant to include a description last night.

From the Flask docs, setting debug=True:

  1. activates the debugger
  2. activates the automatic reloader
  3. enables the debug mode on the Flask application

The automatic reloader is not so important for the purposes of the tutorial, but if users modify the Flask server in anyway and introduce a syntax error for example, debug mode dumps out exceptions to the console instead of swallowing them.

I was working along with the tutorial last night and simply did a copypasta of server.py instead of cloning the repo which resulted in me missing comments.py. When querying the comments endpoint, I got a 500 error, but no useful output in the console:

127.0.0.1 - - [27/Aug/2016 09:05:18] "GET /api/comments HTTP/1.1" 500 -

Meanwhile, if debug mode is enabled, I get a handy Traceback dumped to stdout:

Traceback (most recent call last):
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/path/to/pyenvs/.pyenv/versions/react/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/path/to/pyenvs/code/learn/react/server.py", line 22, in comments_handler
    with open('comments.json', 'r') as f:
IOError: [Errno 2] No such file or directory: 'comments.json'

Although my specific example is a bit contrived as I doubt many other users copy and paste server.py, debug mode is still handy for local development settings. Will update PR description.

@sophiebits
Copy link
Member

Thanks. I knew generally of its behavior but wasn't sure why you'd hit an exception when working through the tutorial. Your explanation makes sense.

@sophiebits sophiebits merged commit 7d0728e into reactjs:master Aug 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants