Open bill-uncultured opened 4 years ago
Same issue as: https://github.com/noirbizarre/flask-restplus/issues/777
The proposed temporary solution is to pin Werkzeug==0.16.1
until a proper fix is put in place.
I have created a fix for this https://github.com/jarus/flask-testing/pull/144
but CI infrastructure is not working
Downloading archive: https://storage.googleapis.com/travis-ci-language-archives/python/binaries/ubuntu/16.04/x86_64/python-2.6.tar.bz2 0.10s$ curl -sSf --retry 5 -o python-2.6.tar.bz2 ${archive_url} curl: (22) The requested URL returned error: 404 Not Found
Another fix would be to edit the flask_testing/utils.py
on line 35:
Use
from werkzeug.utils import cached_property
instead of
from werkzeug import cached_property
There's already a (closed) MR: https://github.com/jarus/flask-testing/pull/146
And an open one: https://github.com/jarus/flask-testing/pull/145
Edit: https://github.com/jarus/flask-testing/pull/145 has been merged
Any updates regarding CI?
As it is fixed. Could you release a new version? :)
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (C:\Users\BABA\PycharmProjects\Automation\venv\lib\site-packages\werkzeug__init__.py)
I am getting this error message
from flask import Flask from flask_restplus import Api, Resource from werkzeug.utils import *
app = Flask(name) api = Api(app)
@api.route('/language') class Language: def get(self): return {'hey': 'there'}
if name == "main": app.run(debug=True)
I've fixed this with:
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
I've fixed this with:
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
Thanks! This works.
fyi: this issue has been fixed in version 0.8.0
Updating to Werkzeug==0.16.1 has fixed.
from werkzeug.utils import cached_property
Still happening when upgrading to 1.0.1 version
Still happening as of today.
Still broken with werkzeug==1.0.1 as of 4th Sept 2020
Can be fixed by adding
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
before importing flask_restplus
Thanks @SidJain1412!
User-side workaround when not expecting to call werkzeug directly:
try:
from flask_restplus import Resource, Api
except ImportError:
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
from flask_restplus import Resource, Api
This is still an issue. My API backend still fails when using untampered Flask due to "cannot import name 'cached_property' from 'werkzeug'".
This is still an issue.
ontology_1 | File "./get_title_details.py", line 1, in
If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)
Werkzeug==2.0.1 Flask==2.0.1 flask-restplus==0.13.0
With this requirements, the issue is still there, I downgraded to Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.
Werkzeug==2.0.1 Flask==2.0.1 flask-restplus==0.13.0
With this requirements, the issue is still there, I downgraded to Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.
When I downgrade it says: flask 2.0.1 requires Werkzeug>=2.0, but you'll have werkzeug 0.16.1 which is incompatible.. Any suggestions?
+1 Any ideas on how to resolve this? Haven't been able to solve the issue with the responses above and downgrading is not an option due to flask 2.0.1 not being compatible.
Flask==2.0.1 Flask-RESTful==0.3.9 Flask-Testing==0.7.1 Werkzeug==2.0.1
Traceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/unittest/loader.py", line 434, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/local/lib/python3.7/unittest/loader.py", line 375, in _get_module_from_name
__import__(name)
File "/usr/src/app/project/tests/test_account_model.py", line 6, in <module>
from project.tests.base import BaseTestCase
File "/usr/src/app/project/tests/base.py", line 4, in <module>
from flask_testing import TestCase
File "/usr/local/lib/python3.7/site-packages/flask_testing/__init__.py", line 13, in <module>
from .utils import TestCase, LiveServerTestCase
File "/usr/local/lib/python3.7/site-packages/flask_testing/utils.py", line 35, in <module>
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/usr/local/lib/python3.7/site-packages/werkzeug/__init__.py)
If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)
100%. I can't believe this is still going on.
Yes
On Tue, 13 Jul, 2021, 9:19 am toddman2, @.***> wrote:
If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)
100%. I can't believe this is still going on.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jarus/flask-testing/issues/143#issuecomment-878755563, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALR2PCSCNX3Y2TKMUKDSPDDTXOZWHANCNFSM4KRE6NPQ .
Maybe related: Switch locals to be based on ContextVars #1778 https://github.com/pallets/werkzeug/pull/1778 pgjones commented on Mar 28, 2020 • ContextVar was introduced in Python 3.7 and is effectively the same as Local in Werkzeug (although a different API). They should work in Greenlet and threading contexts as before but also now in asyncio or other async/await contexts.
The storage attribute has been kept for backwards compatibility (even though it is a dunder it seems it is used, e.g. in tests).
The ident_func though must be deprecated as this is now handled by the ContextVar. This may cause some backwards incompatibility.
Is there a solution to this problem? Because the first mention with Flask==2.0.1, flask-restplus==0.13.0, Werkzeug==2.0.1 was in June. This bug has yet to be resolved?
The issue still persists as of today... temporary workaround:
try:
from flask_restplus import Api, Resource
except ImportError:
import werkzeug, flask.scaffold
werkzeug.cached_property = werkzeug.utils.cached_property
flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
from flask_restplus import Api, Resource
Current requirements.txt
Flask==2.1.2
Flask-Assets==2.0
flask-restplus==0.13.0
Werkzeug==2.1.2
and applied work around as (Downgrade is not possible due to compatibility)
try:
from flask_restplus import Api, Resource,Namespace
except ImportError:
import werkzeug, flask.scaffold
werkzeug.cached_property = werkzeug.utils.cached_property
flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
from flask_restplus import Api, Resource,Namespace
from models.hello_world import helloWork
data_edits_namespce=Namespace('data_edits')
data_edits_namespce.add_model('HelloWorld',helloWork)
Now the exception is coming
from flask_restplus import Api, Resource,Namespace
venv/lib/python3.10/site-packages/flask_restplus/model.py", line 8, in <module> from collections import OrderedDict, MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)
Not sure what i am missing here , does any one else also faced same issue
We all should be migrating to flask-restx which is a wrapper for this library and it's been actively maintained.
Clearly seems the owner is busy these days or no longer has an interest in fixing this. I'm cutting the guy some slack -- it's been a useful package so far. It would be appreciated if he could check in with us one way or another. Thanks for all your time you've put into so far.
"
The temporary solution isn't possible. "pin Werkzeug==0.16.1 until a proper fix is put in place."
werkzeug just released 1.0.0, and the deprecated werkzeug.cached_property has been removed in favor of werkzeug.utils.cached_property.
This was addressed in October by pull request # 141, but it seems like it failed testing because the old python 3.3 and 2.6 couldn't be downloaded.