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

Unable to start flask3.0 app on a minimal implementation with invalid syntax. Perhaps you forgot a comma? (scaffold.py, line 295) #5456

Closed
lazydreamerbliss opened this issue Apr 6, 2024 · 2 comments

Comments

@lazydreamerbliss
Copy link

lazydreamerbliss commented Apr 6, 2024

Simply create a minimal flask3.0 app as follow and execute it, it will fail instantly on importing from flask import Flask:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

app.run()

Error trace:

Traceback (most recent call last):
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/lazydreamer/.vscode-server/extensions/ms-python.debugpy-2024.4.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/home/lazydreamer/Dev/TestProj/src/main.py", line 3, in <module>
    from app import flask_app
  File "/home/lazydreamer/Dev/TestProj/src/app.py", line 1, in <module>
    from flask import Flask
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/site-packages/flask/__init__.py", line 6, in <module>
    from .app import Flask as Flask
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/site-packages/flask/app.py", line 43, in <module>
    from .sansio.app import App
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/site-packages/flask/sansio/app.py", line 31, in <module>
    from .scaffold import _endpoint_from_view_func
  File "/home/lazydreamer/anaconda3/envs/test_env/lib/python3.11/site-packages/flask/sansio/scaffold.py", line 295
    raise TypeError('Use the 'route' decorator to use the 'methods' argument.')
                    ^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

image

I am not sure what does the exception message 'Use the 'route' decorator to use the 'methods' argument.' means as I've just upgraded to Flask3.0, but this message string is definitely not right, and I my project will not encounter any issue on Flask2.3.3.

Environment:

  • Python version: 3.11.8
  • Flask version: 3.0.2
  • OS: Ubuntu
@lazydreamerbliss lazydreamerbliss changed the title Unable to start flask app on a minimal implementation with invalid syntax. Perhaps you forgot a comma? (scaffold.py, line 295) Unable to start flask3.0 app on a minimal implementation with invalid syntax. Perhaps you forgot a comma? (scaffold.py, line 295) Apr 6, 2024
@davidism
Copy link
Member

davidism commented Apr 6, 2024

I can't reproduce that issue with the information provided. Perhaps there's something wrong with your Python environment.

@davidism davidism closed this as completed Apr 6, 2024
@HipsterSantos
Copy link

Instead try inside virtual env and then reinstall everything after that run again if pass , it means that the problem is on you system config for python @lazydreamerbliss

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants