Python 如何修复flask test_client().post()中的json解码错误?
我试图为Flask JSON API编写一个测试套件,但似乎无法将{form_id:data}传递到app.test_client post方法的JSON=参数中 {form_i:data}运行良好,我尝试过设置各种编码选项,但没有任何运气Python 如何修复flask test_client().post()中的json解码错误?,python,flask,Python,Flask,我试图为Flask JSON API编写一个测试套件,但似乎无法将{form_id:data}传递到app.test_client post方法的JSON=参数中 {form_i:data}运行良好,我尝试过设置各种编码选项,但没有任何运气 with app.test_client() as c: test_call = c.post("api/signup/", json={'form_id': 'hi'}) 给出以下错误消息: json.decoder.JSONDecodeError:
with app.test_client() as c:
test_call = c.post("api/signup/", json={'form_id': 'hi'})
给出以下错误消息:
json.decoder.JSONDecodeError: Expecting value: line 8 column 4 (char 123)
向你推荐这个
import json
with app.test_client() as c:
test_call = c.post("api/signup/",
data=json.dumps({'form_id': 'hi'}),
content_type='application/json')
Nevermind则是另一个错误–调用单独的JSON文件时忘记删除尾随逗号…您使用的是什么版本的Flask?Flask 1.0.2与Python 3.7.0
@app.route('api/signup', methods=['post'])
def signup():
json = request.json