--Flask-RESTPlus seems to stop maintenance, and if you continue to use it, its fork, Flask-RESTX, looks good.
--For existing code, just replacing flask_restplus
with flask_restx
worked.
--The parameter name also needed to be changed to reflect the config settings
I was developing a little Web API server in Flask and documented the API specification in Swagger using Flask-RESTPlus. The development on the Flask side has been calm and I haven't touched it for the past month or so, but an error occurred when I tried to check the operation with a slight modification.
When I check the log, it is moss in the werkzeug package. The level is not near the correction point.
../../../../.pyenv/versions/3.6.9/envs/testenv/lib/python3.6/site-packages/flask_restplus/fields.py:17: in <module>
from werkzeug import cached_property
E ImportError: cannot import name 'cached_property'
Certainly, in the past month or so, I had deleted the virtualenv at hand for various reasons, and recreated it at the timing of this correction. I've reinserted the package in pip's requirements.txt, but something may be happening due to version dependencies.
If you google, the issue on Github will be a hit. It looks like this. flask-restplus is broken by Werkzeug 1.0.0 #777
Cached_property
moved from under werkzeug
to under werkzeug.utils
when Werkzeug went to version 1.0.0 in early February 2020. Since flask_restplus
was used by importing cached_property
, it seems that the above error occurred.
Flask's package dependencies are written as Werkzeug> = 0.15
, so installing pip modules from scratch will be affected by a major version upgrade of Werkzeug.
Looking at the README.md of Flask-RESTPlus Github page again, the following description is at the beginning. It was added around the beginning of January 2020.
IMPORTANT NOTICE:
This project has been forked to
Flask-RESTX <https://github.com/python-restx/flask-restx>
_ and will be maintained by by thepython-restx <https://github.com/python-restx>
_ organization. Flask-RESTPlus should be considered unmaintained.
Flask-RESTPlus will no longer be maintained, the fork Flask-RESTX will be maintained in the future. And that.
It would be nice to manually lower the version of Werkzeug, but I thought that development would continue for a while, so I decided to try Flask-RESTX. As far as the Flask-RESTX page is concerned, the usage is almost the same as Flask-RESTPlus, and it looks good. So I tried to move it by simple replacement for the time being. The code looks like this.
flask_restplus
from flask_restplus import Namespace, fields, Resource
from flask_restplus.namespace import HTTPStatus
flask_restx
from flask_restx import Namespace, fields, Resource
from flask_restx.namespace import HTTPStatus
With this alone, it came to work without outputting an error for the time being. Flask-RESTX uses the latest version of PyPI, 0.1.1. It has a limitation of werkzeug (<= 0.16.1), so it seems that the problem will be solved by reinstalling the pip package.
After checking the latest code on Github, it seems that werkzeug 1.0.0 is okay with the import writing method modified. I hope PyPI will reflect this version in the future.
I changed the setting in config to the default or a little, but this also did not reflect the setting unless I changed the key name of dict. This also just changes RESTPLUS_
to RESTX_
, so it's helpful to be mechanical.
flask_restplus
app.config['RESTPLUS_MASK_SWAGGER'] = False
app.config['RESTPLUS_JSON'] = {'ensure_ascii': False}
flask_restx
app.config['RESTX_MASK_SWAGGER'] = False
app.config['RESTX_JSON'] = {'ensure_ascii': False}
Recommended Posts