使用test_客户端并发送如下请求:
app = Flask(__name__)
client = app.test_client()
headers = {'content-type': 'application/json', 'Authorization': u'Bearer fake_token_123'}
params = {'dont_care': True}
client.get(ֿֿ'/my_route/123', query_string=params, headers=headers)
我的路线是
^{pr2}$parser.parse_args()
失败
The browser (or proxy) sent a request that this server could not understand
将'content-type': 'application/json'
从header中移除时,它起作用。在
我不明白这种行为,如果没有不优雅的try, expect
,我该如何防范它。在
谢谢你的帮助
您已经发现了如何修复它:如果不发布JSON,请不要发送
content-type: application/json
。不能用GET发送JSON,即使可以(或使用POST),也必须先用json.dumps(data)
对JSON进行编码。在相关问题 更多 >
编程相关推荐