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

Document breaking change that underlying Flask app can no longer be run directly. #1794

Closed
tariqjamal-abdulazeez opened this issue Nov 7, 2023 · 10 comments · Fixed by #1815

Comments

@tariqjamal-abdulazeez
Copy link

tariqjamal-abdulazeez commented Nov 7, 2023

Description

When using connexion and flask with the below version

Name: Flask
Version: 3.0.0

Name: connexion
Version: 3.0.1

Code

app.py code
import connexion
def post_greeting(name: str) -> str:
return f"Hello {name}"

api = connexion.FlaskApp(name, specification_dir="specs/")
api.add_api("openapi.yml", arguments={"title": "Hello World Example"})
app = api.app

openapi.yml

openapi.yml

openapi: 3.0.0
info:
title: Hello World Example
version: "1.0"
servers:

  • url: /api
    description: Development API Location
    paths:
    /post_greeting:
    get:
    summary: Get a greeting
    parameters:
    - name: name
    in: query
    schema:
    type: string
    description: Name to be used in the greeting
    responses:
    '200':
    description: OK
    content:
    application/json:
    schema:
    type: object
    properties:
    message:
    type: string

Actual behaviour

`During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/werkzeug/serving.py", line 362, in run_wsgi
execute(self.server.app)
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/werkzeug/serving.py", line 323, in execute
application_iter = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/flask/app.py", line 1478, in call
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/flask/app.py", line 1458, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/flask/app.py", line 1455, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/flask/app.py", line 869, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/flask/app.py", line 759, in handle_user_exception
return self.ensure_sync(handler)(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tariqjamal/anaconda3/envs/reflex-apps/lib/python3.11/site-packages/connexion/apps/flask.py", line 245, in _http_exception
raise starlette.exceptions.HTTPException(exc.code, detail=exc.description)
starlette.exceptions.HTTPException: 404
`

@spec-first
@RobbeSneyders @Ruwann Like this in another project i'm getting the error

raise NotFound() from None

werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

@RobbeSneyders
Copy link
Member

Hi @tariqjamal-abdulazeez, how are you running the application? You should run the Connexion application directly, not the underlying Flask application.

@shariqueakbare
Copy link

@tariqjamal-abdulazeez how to achieve that because i have exactly the same issue !

@nickzandbergen
Copy link

I had a similar issue after upgrading from 2.14.0 and using connexion's FlaskApp instead of the Flask application fixed it.

@RobbeSneyders
Copy link
Member

Check this discussion for more info #1795

@RobbeSneyders RobbeSneyders changed the title starlette.exceptions.HTTPException: 404 Document breaking change that underlying Flask app can no longer be run directly. Nov 7, 2023
@tariqjamal-abdulazeez
Copy link
Author

I had a similar issue after upgrading from 2.14.0 and using connexion's FlaskApp instead of the Flask application fixed it.

I had a similar issue after upgrading from 2.14.0 and using connexion's FlaskApp instead of the Flask application fixed it.

@

Hi @tariqjamal-abdulazeez, how are you running the application? You should run the Connexion application directly, not the underlying Flask application.

@RobbeSneyders I tried that also but it does not work for me

@tariqjamal-abdulazeez
Copy link
Author

I had a similar issue after upgrading from 2.14.0 and using connexion's FlaskApp instead of the Flask application fixed it.

@nickzandbergen I need to achieve this thing in connexion latest version, but using the connexion latest docs with flask version 3.0 it not working properly

@tariqjamal-abdulazeez
Copy link
Author

@RobbeSneyders Could you write a documentation for migration step by step ? because really i'm not able to make it works with the new version

@RobbeSneyders
Copy link
Member

It's hard to write a general guide since users were using Connexion in many different ways. We spent a great amount of effort to update and improve our documentation for Connexion 3. Please try to use it to find your answers there.

If you run into specific errors, you can open an issue explaining the error and we can support on that error specifically. If we notice any gaps in our documentation based on these issues, we will update it.

@tariqjamal-abdulazeez
Copy link
Author

It's hard to write a general guide since users were using Connexion in many different ways. We spent a great amount of effort to update and improve our documentation for Connexion 3. Please try to use it to find your answers there.

@RobbeSneyders Previously i had working with flask=2.2.5 and connexion = 2.14.2 with this configuration the application request are correctly but due to some dependency i had upgraded the both package to their latest version, but in that the request are correctly getting in server and flask before_request is executed after then when it try to match the url with openapi duing that getting the issue

I had tried all possible according to the docs but it doesn't work for me

@tianjing-li
Copy link

I actually have the same configuration as @tariqjamal-abdulazeez and trying to figure out how to upgrade to [email protected].

Here's how my Flask app entrypoint looks like:

def create_app() -> connexion.FlaskApp:
    app = connexion.FlaskApp(__name__, specification_dir="../../openapi/")
    app.add_api(
        API_VERSION,
        resolver=connexion.resolver.RelativeResolver("provider.app"),
    )
    logging.basicConfig(level=logging.INFO)
    flask_app = app.app
    config_prefix = os.path.split(os.getcwd())[
        1
    ].upper()  # Current directory name, upper-cased
    flask_app.config.from_prefixed_env(config_prefix)
    return flask_app

I also use poetry as a package dependency manager, and run the server with poetry run flask --app provider --debug run, but I can see from the above that we can't run the flask server directly but instead need to use Connexion? Is this achieved by using uvicorn? Ie: I will need to add uvicorn as a dependency and then use that for starting the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants