Flask==1.1.1 pymongo==3.10.1 flask-restplus==0.13.0我正在尝试将JSON放到URL并使用,但我遇到了一个问题。在 routes.py 我有一个简单的API设置...update()@api.route('/api/content/<idx>')class UpdateContent(Resource): def put(self,idx): data = api.payload Content.objects(content_id=idx).update(**data) return jsonify(Content.objects(content_id=idx))使用Postman I are PUTting to /api/content/2 { "content_id": 2, "title": "Test 2", "description": "Test 2" }我收到这个...Traceback (most recent call last): File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/app.py", line 2463, in __call__ return self.wsgi_app(environ, start_response) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/app.py", line 2449, in wsgi_app response = self.handle_exception(e) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask_restplus/api.py", line 584, in error_router return original_handler(e) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/app.py", line 1866, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/_compat.py", line 38, in reraise raise value.with_traceback(tb) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/jyoseph/Sites/testsite/venv/lib/python3.8/site-packages/flask_restplus/api.py", line 584, in error_router return original_handler(e)
1 回答
偶然的你
TA贡献1841条经验 获得超3个赞
您遇到的问题可能是由于对象中不存在一些其他键作为字段引起的。data
使用字典解包时,请确保要解压缩到参数的所有键确实位于要更新的 MongoDB 对象中。
添加回答
举报
0/150
提交
取消