connexion: ImportError: cannot import name 'FileStorage' from 'werkzeug'
Description
Getting below import error when using connexion 1.1.15 cannot import name ‘FileStorage’ from ‘werkzeug’
Expected behaviour
import connexion should work without issues
Actual behaviour
File “/opt/bitnami/python/lib/python3.7/site-packages/connexion/decorators/validation.py”, line 9, in <module> from werkzeug import FileStorage ImportError: cannot import name ‘FileStorage’ from ‘werkzeug’ (/opt/bitnami/python/lib/python3.7/site-packages/werkzeug/init.py)
Steps to reproduce
pip install connexion == 1.1.15
import connexion
Additional info:
The issue started on Feb 7, 2020 as werkzeug ver 1.0.0 released. werkzeug is a dependency of connexion and ver 1.0.0 is installed as a pre-requisite from Feb 07, 2020. Workaround : Install werkzeug ver 0.16.1 before installing connexion
Output of the commands:
python --versionPython 3.7.4pip show connexion | grep "^Version\:"Version: 1.1.15
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 19
- Comments: 20 (3 by maintainers)
Commits related to this issue
- Force old version of werkzeug Due to this issue https://github.com/zalando/connexion/issues/1149 — committed to UnivaCorporation/unisight-visualizations by cameronbrunner 4 years ago
- Fix for https://github.com/zalando/connexion/issues/1149 — committed to ow2-proactive/docker by andrewssobral 4 years ago
- Fix for https://github.com/zalando/connexion/issues/1149 — committed to ow2-proactive/docker by andrewssobral 4 years ago
- Add explicit werkzeug dependency Fixes #1149. — committed to patrickkwang/connexion by deleted user 4 years ago
- Add explicit werkzeug dependency (#1302) Fixes #1149. — committed to spec-first/connexion by patrickkwang 3 years ago
We were using
connexion==2.2.0and started getting this error. Usingconnexion==2.6.0(without specifying anywerkzeugdependencies) solved the problem.@jmcs thanks. Using latest version +
werkzeug==0.16.1solved this problem.Looks like they moved the FileStorage under datastructrues.
Solved the problem for me.
Here is the documentation.
https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/
I know this doesn’t help in any way whatsoever, but Python is just broken in so many ways when you want to use it for production stuff.
It never works. It’s extremely confusing what version of python to use, what virtualenv tool (virtualenv, pipenv, …) , what package manager (pip, pip3, conda, easy_install, …), where actual configuration is stored…
In my opinion, it was a huge mistake to allow two supported versions of python to co-exist. I know I know, backwards compatibility, but honestly, when production software makes use of such code:
it’s just broken and needs to be dropped.
What we actually have right now are Linux servers full of two versions of Python (2 and 3) that are not compatible with each other. It’s a huge problem.
This has already been fixed with https://github.com/zalando/connexion/pull/1044
This is still an issue. cc @patrickkwang
Swagger codegen for flask emits
requirements.txtwithconnexion == 2.2.0. Out-of-the-box, that fails to install due toconnexionnot declaring dependency onto Werkzeug while directly using it:https://github.com/zalando/connexion/blob/a0ac0fd13f6857bba2563fbdda55404cfa69dde3/connexion/decorators/validation.py#L9
Off course, since the dependency is not declared (and so, not constrained) — the indirectly-updated-via-flask Werkzeug 1.0 move
werkzeug.FileStorage→werkzeug.datastructures.FileStoragebreaks it. @cognifloyd correctly notices the problem, too.OK the poor programmer sighs, maybe googles this issue, tweaks the
requirements.txtthat Swagger generated (anyone cares to send them a patch bumping upconnexion?)… only to kiss another error:Long story short, with this I was able to also run
toxtests on Python 3.8 in an OpenAPI swagger-generated server project:In fast-moving ecosystems, not following basic dependency management hygiene leads to issues exactly like this. Take it as a lesson “how not to”.
Hmm. It looks like connexion needs to declare werkzeug as a direct dependency and not rely on our dep to flask to pull that in.
My use case is a Flask Swagger API
I pinned to the following packages and my build resolved the issue.
To help those that might be searching for this, here is my error
While this might not be THE solution, it seems to have worked for me at this time.
I’ll be experimenting with different versions but since this is a fresh issue popping up, I wanted to get something out here to help those pulling their hair out.
Just by pinning connexion==2.6.0 in requirements.txt file fixed the issue!