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

[BUG][python] python-flask server ImportError exception at launch #11855

Open
3 of 6 tasks
MiltiadisKoutsokeras opened this issue Mar 11, 2022 · 0 comments
Open
3 of 6 tasks

Comments

@MiltiadisKoutsokeras
Copy link

MiltiadisKoutsokeras commented Mar 11, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Generating server code with python-flask and launching the program leads to ImportError exception: ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.10/site-packages/itsdangerous/__init__.py). This is probably caused by the following:

pallets/flask#4455
pallets/markupsafe#284

Full stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/test_rest_api/__main__.py", line 5, in <module>
    from test_rest_api import encoder
  File "/usr/src/app/test_rest_api/encoder.py", line 1, in <module>
    from connexion.apps.flask_app import FlaskJSONEncoder
  File "/usr/local/lib/python3.10/site-packages/connexion/apps/flask_app.py", line 11, in <module>
    import flask
  File "/usr/local/lib/python3.10/site-packages/flask/__init__.py", line 19, in <module>
    from . import json
  File "/usr/local/lib/python3.10/site-packages/flask/json/__init__.py", line 15, in <module>
    from itsdangerous import json as _json
ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.10/site-packages/itsdangerous/__init__.py)
openapi-generator version

Latest Docker image

openapi-generator-cli 6.0.0-SNAPSHOT
  commit : 6f37409
  built  : 2022-03-10T08:57:57Z
OpenAPI declaration file content or url

Reproduced with any specification file. It does not depend on OpenAPI definitions.

Generation Details
docker run --name "openapi-generator-cli" --rm -u $(id -u ${USER}):$(id -g ${USER}) --mount type=bind,src=$(pwd),dst=/host openapitools/openapi-generator-cli:latest generate --input-spec /host/openapi.yaml --generator-name python-flask --config /host/python-flask-config.yaml --output /host/output/python-flask/
Steps to reproduce
docker run --name "openapi-generator-cli" --rm -u $(id -u ${USER}):$(id -g ${USER}) --mount type=bind,src=$(pwd),dst=/host openapitools/openapi-generator-cli:latest generate --input-spec /host/openapi.yaml --generator-name python-flask --config /host/python-flask-config.yaml --output /host/output/python-flask/

cd output/python-flask/

docker build -t test_rest_api .

docker run -p 5000:5000 test_rest_api
Related issues/PRs

None.

Suggest a fix

It can be fixed by changing the Flask version and setting a specific MarkupSafe version as suggested in the relevant issues of above. So manually editing the requirements.txt file from this:

connexion[swagger-ui] >= 2.6.0; python_version>="3.6"
# 2.3 is the last version that supports python 3.4-3.5
connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4"
# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug
# we must peg werkzeug versions below to fix connexion
# https://github.com/zalando/connexion/pull/1044
werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask == 1.1.2

to this

connexion[swagger-ui] >= 2.6.0; python_version>="3.6"
# 2.3 is the last version that supports python 3.4-3.5
connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4"
# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug
# we must peg werkzeug versions below to fix connexion
# https://github.com/zalando/connexion/pull/1044
werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask == 1.1.4
MarkupSafe == 2.0.1

Fixes the issue.

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

No branches or pull requests

2 participants