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

populate routes with gunicorn (connexion 3.0.0a7) #1755

Closed
jdkent opened this issue Oct 25, 2023 · 2 comments · Fixed by #1766
Closed

populate routes with gunicorn (connexion 3.0.0a7) #1755

jdkent opened this issue Oct 25, 2023 · 2 comments · Fixed by #1766

Comments

@jdkent
Copy link
Contributor

jdkent commented Oct 25, 2023

Description

When starting the flask app with gunicorn, the connexion app does not initialize routes. Is there another way to initialize the connexion app while running the flask app with gunicorn?

example:

import logging
from pathlib import Path

import connexion
from connexion.resolver import MethodViewResolver

logging.basicConfig(level=logging.INFO)

zoo = {
    1: {
        "id": 1,
        "name": "giraffe",
        "tags": ["africa", "yellow", "hoofs", "herbivore", "long neck"],
    },
    2: {
        "id": 2,
        "name": "lion",
        "tags": ["africa", "yellow", "paws", "carnivore", "mane"],
    },
}


app = connexion.FlaskApp(__name__, specification_dir="spec/")

options = {"swagger_ui": True}
app.add_api(
    "openapi.yaml",
    options=options,
    arguments={"title": "MethodViewResolver Example"},
    resolver=MethodViewResolver(
        "api",
        # class params are entirely optional
        # they allow to inject dependencies top down
        # so that the app can be wired, in the entrypoint
        class_arguments={"PetsView": {"kwargs": {"pets": zoo}}},
    ),
    strict_validation=True,
    validate_responses=True,
)

# get access to the flask app
flask_app = app.app

if __name__ == "__main__":
    app.run(f"{Path(__file__).stem}:app", port=8080)

Then I ran gunicorn

gunicorn -w 1 -b :8080 app:flask_app --log-level debug --timeout 120

Expected behaviour

http://localhost:8080/openapi/pets

would show pets

Actual behaviour

{
"type": "about:blank",
"title": "Not Found",
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404
}

Steps to reproduce

run script above

Additional info:

Output of the commands:

  • python --version
  • pip show connexion | grep "^Version\:"
@jdkent
Copy link
Contributor Author

jdkent commented Oct 25, 2023

needed to use uvicorn worker-class 😆

gunicorn -w 1 -b :8080 app:flask_app --log-level debug --timeout 120 --worker-class uvicorn.workers.UvicornWorker

@RobbeSneyders
Copy link
Member

Thanks @jdkent, will add this to the documentation.

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

Successfully merging a pull request may close this issue.

2 participants