refer to: https://stackoverflow.com/questions/66647787/attributeerror-cant-set-attribute-when-connecting-to-sqlite-database-with-flas
sqlalchemy version should be set as 1.3.x, rather than 1.4.x by default now
(venv) wuwenxiangs-MacBook-Pro:rest_api_demo wuwenxiang$ python rest_api_demo/app.py
2021-08-11 05:56:50,154 - main - INFO - >>>>> Starting development server at http://localhost:8888/api/ <<<<<
- Serving Flask app "app" (lazy loading)
- Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
- Debug mode: on
2021-08-11 05:56:50,161 - werkzeug - INFO - * Running on http://localhost:8888/ (Press CTRL+C to quit)
2021-08-11 05:56:50,162 - werkzeug - INFO - * Restarting with stat
2021-08-11 05:56:50,510 - main - INFO - >>>>> Starting development server at http://localhost:8888/api/ <<<<<
2021-08-11 05:56:50,514 - werkzeug - WARNING - * Debugger is active!
2021-08-11 05:56:50,519 - werkzeug - INFO - * Debugger PIN: 228-831-182
2021-08-11 05:57:09,343 - werkzeug - INFO - 127.0.0.1 - - [11/Aug/2021 05:57:09] "GET /api/ HTTP/1.1" 200 -
2021-08-11 05:57:09,498 - werkzeug - INFO - 127.0.0.1 - - [11/Aug/2021 05:57:09] "GET /api/swagger.json HTTP/1.1" 200 -
2021-08-11 05:57:15,325 - rest_api_demo.api.restplus - ERROR - An unhandled exception occurred.
Traceback (most recent call last):
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1008, in call
return self.registry[key]
KeyError: <greenlet.greenlet object at 0x1050b4d50 (otid=0x10507ebc0) current active started main>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/api.py", line 309, in wrapper
resp = resource(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/marshalling.py", line 101, in wrapper
resp = f(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/rest_api_demo/api/blog/endpoints/categories.py", line 23, in get
categories = Category.query.all()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 500, in get
return type.query_class(mapper, session=self.sa.session())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/orm/scoping.py", line 47, in call
return self.registry()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1010, in call
return self.registry.setdefault(key, self.createfunc())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 771, in create_session
return SignallingSession(self, **options)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 155, in init
bind = options.pop('bind', None) or db.engine
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 893, in engine
return self.get_engine(self.get_app())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 910, in get_engine
return connector.get_engine()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 542, in get_engine
self._sa.apply_driver_hacks(self._app, info, options)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 877, in apply_driver_hacks
info.database = os.path.join(app.root_path, info.database)
AttributeError: can't set attribute
2021-08-11 05:57:15,328 - rest_api_demo.api.restplus - ERROR - An unhandled exception occurred.