connexion icon indicating copy to clipboard operation
connexion copied to clipboard

Making debug=True in flask is not working

Open mohithg opened this issue 8 years ago • 7 comments

Description

Adding debug=True in app.run in flask server is not working

Expected behaviour

Ideally it should start the server in debug mode

Actual behaviour

 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "/Users/mohithg/Downloads/python-flask-server/swagger_server/__main__.py", line 5, in <module>
    from swagger_server import encoder
ModuleNotFoundError: No module named 'swagger_server'

Steps to reproduce

Autogenerate any swagger template, and in main.py change the app.run(port=8080, debug=True)

Additional info:

python 3.6 connexion Version: 1.1.15

Output of the commands:

  • python --version
  • pip show connexion | grep "^Version\:"

mohithg avatar Jun 11 '18 10:06 mohithg

Hey @mohithg, I was able to reproduce your error using the swagger-codegen flaskConnexion example.

It turns out this is an old werkzeug bug related to using the python3 -m swagger_server syntax. You can work around it by setting the python path.

PYTHONPATH=$PWD:$PYTHONPATH python3 swagger_server

dtkav avatar Jul 02 '18 05:07 dtkav

Thanks @dtkav that works!

mohithg avatar Jul 03 '18 05:07 mohithg

Thanks, @dtkav this worked for me as well!

slonak79 avatar Aug 09 '18 16:08 slonak79

With all due respect, given that this doesn't happen in regular Flask but happens in Connexion I'd argue this is a bug in Connexion, and it should be fixed. Blaming this on something two steps upstream (Werkzeug) is not fair, especially given that the package directly upstream (Flask) doesn't have this bug.

Looking into this further, it's not accurate to call this a bug in Werkzeug, it's a direct consequence of how Python works (treating called modules differently than called files) which means it's probably not going to change any time soon. So, unless you think it's acceptable for debug mode to be broken and require a workaround permanently, I hope you'll consider reopening this.

jonbirge avatar Feb 12 '19 21:02 jonbirge

It sounds like you had a good idea of what's happening, do you mind creating a pull request? I'm happy to review it.

I was unaware of the context you provided. I just put in a few minutes of my day to try to help out.

swagger-codegen is an unrelated project that seems to generate projects that are different from our examples (and certainly my workflow), so we receive tickets often of the form "my code that was generated by swagger-codegen is broken", and I'm often not sure if the problem originates in connexion or not.

dtkav avatar Feb 12 '19 21:02 dtkav

I'm happy to submit a PR if I can figure out how to fix this, but I'm pretty new to Flask/Connexion. In fact, the fact that debugging is broken out of the box is part of what I found frustrating as a new user. Having to dig into obscure bugs at the same time you're trying to learn something isn't exactly welcoming! I know these things are sometimes impossible to fix, but I was just trying to make the case for at least keeping the issue open, because that's the only way it will get fixed.

jonbirge avatar Feb 15 '19 14:02 jonbirge

Is there a reason why it wouldn't work to just programmatically ensure that the directory in which the entry point resides is prepended to the Python path before the server starts?

jonbirge avatar Feb 15 '19 15:02 jonbirge