Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11855
Closed
Open
Issue created Mar 11, 2022 by Administrator@rootContributor3 of 6 checklist items completed3/6 checklist items

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

Created by: MiltiadisKoutsokeras

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:

https://github.com/pallets/flask/issues/4455 https://github.com/pallets/markupsafe/issues/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.

Assignee
Assign to
Time tracking