尝试将dictionary对象传入请求时,RequestParser
抛出400错误,并使用{error\u msg}返回以下错误:
dictionary update sequence element #0 has length 1; 2 is required
我试图分析参数的方式如下:
patch_parser = reqparse.RequestParser()
# ...
patch_parser.add_argument("labels", type=dict, help="{error_msg}", store_missing=False)
# some POST/PUT request function
@app.route('/path/<id:int>')
def someFunction():
args = patch_parser.parse_args()
# ...
提出请求之前的代码:
toUpdateWith = {"name": "Test", "description": "This is a test."}
toUpdateWith['labels'] = { "4" : "create"}
response = self.conn.post('/path/2', data=toUpdateWith)
传入的数据为:
{
"name": "Test",
"description": "This is a test.",
"labels": {
"4": "create"
}
}
虽然这可以通过Postman正常工作,但当以编程方式执行时,它不起作用。那么,为什么会发生此错误呢
如果我遗漏了什么信息,请告诉我
如果希望参数采用字典,则需要通过json传递数据
相关问题 更多 >
编程相关推荐