HTTP令牌生成在Python请求中不起作用

时间:2020-06-25 19:03:59

标签: python json curl python-requests

所以我用curl编写了这个脚本以生成令牌

token=$(curl -s -H "Accept: application/json" -H "Content-Type: application/json" --data '{"identifier": "...", "password": "..."}' "$HOST:$PORT/login" | ggrep -Po '"token":"(\K[^"]+)')

效果很好。但是,由于Python 3的简单性,我想使用请求执行相同的任务。据我了解,跑步

import requests, json
http = '...'
head = {'accept': 'application/json', 'Content-Type':'application/json'}
data = { 'username' : '...', 'password' : '...' }
r = requests.post(http, data=json.dumps(data), headers=head, verify=False)
print(r.text)

应该返回相同的内容,但出现错误

{"id":"3bca1f46-0577-40a9-8e09-7d68557ad88f","rafalError":"WrongJson","message":"DecodingFailure at .identifier: Attempt to decode value on failed cursor"}

r.status_code返回422。

0 个答案:

没有答案