requests请求中data字段中字典的问题
data='reqData=%7b%22source%22%3a2%2c%22riskDeviceParam%22%3a%22%7b%5c%22eid%5c%22%3a%5c%22PXAXFRJARCJIU6WL3PNRDOE4NFK77RIICWP2WHHSN7TCEOBP433N45AVCLOEEEAVZMN5WX4RCUEVEQ7UVQP6VS75WI%5c%22%2c%5c%22fp%5c%22%3a%5c%221fe6f026938fa0b7a758afcf997fc602%5c%22%2c%5c%22sdkToken%5c%22%3a%5c%22jdd012J3LKEZK6HH3JJBH6RMUDWXBHUR4GP3R3HURPPE2XYTXC4QFDN76M4TLWMKRXHX36SJPMBRTNOGAGEAMVGKZSWCEEWAYJQC2IW3FTBA01234567%5c%22%2c%5c%22token%5c%22%3a%5c%22EL2EAPOHSUELMT63JICOTOBOAJNY54SYPKVTH6EKX233HE7QEGRRFK3JQJMRM5TWJLM3GPRMND6P4%5c%22%2c%5c%22jstub%5c%22%3a%5c%227CPGDYQVPPCXJSHUUFS2ZY47TKZNXDPKRHVGYACI2R4VIUWSFHUDJQXIRCV7EA3AB5S4LUO344EQIDI4HRAPNZT6IYKFOGZ3EUKJJFA%5c%22%7d%22%7d'requests.post(url=url,headers=head, data=(data)).text
返回
{"msg":"成功","code":"200"
但把字段解码后
data={reqData={"source":2,"riskDeviceParam":"{\"eid\":\"PXAXFRJARCJIU6WL3PNRDOE4NFK77RIICWP2WHHSN7TCEOBP433N45AVCLOEEEAVZMN5WX4RCUEVEQ7UVQP6VS75WI\",\"fp\":\"1fe6f026938fa0b7a758afcf997fc602\",\"sdkToken\":\"jdd012J3LKEZK6HH3JJBH6RMUDWXBHUR4GP3R3HURPPE2XYTXC4QFDN76M4TLWMKRXHX36SJPMBRTNOGAGEAMVGKZSWCEEWAYJQC2IW3FTBA01234567\",\"token\":\"EL2EAPOHSUELMT63JICOTOBOAJNY54SYPKVTH6EKX233HE7QEGRRFK3JQJMRM5TWJLM3GPRMND6P4\",\"jstub\":\"7CPGDYQVPPCXJSHUUFS2ZY47TKZNXDPKRHVGYACI2R4VIUWSFHUDJQXIRCV7EA3AB5S4LUO344EQIDI4HRAPNZT6IYKFOGZ3EUKJJFA\"}"}}
requests.post(url=url,headers=head, data=(data)).text
返回
"msg":"服务器繁忙,请稍后再试试","code":"500"
改成data=json.dumps(data)也一样,这个是什么问题啊 {:10_266:} 本帖最后由 suchocolate 于 2021-3-26 18:46 编辑
code 500是服务器问题。
服务器可能本来就需要url编码后的数据,原文本可能不支持。
Post到服务器的数据往往需要编码哦~
Url编码方式 推荐使用 urllib.parse.urlencode
页:
[1]