5

【踩坑】Python3 通过 requests 包发请求报错

 9 months ago
source link: https://loli.fj.cn/2023/08/09/Python3%E9%80%9A%E8%BF%87requests%E5%8C%85%E5%8F%91%E8%AF%B7%E6%B1%82%E6%8A%A5%E9%94%99/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【踩坑】Python3 通过 requests 包发请求报错

2023-08-09

Python3 通过 requests 包发请求报错:JSON parse error: Unrecognized xxx: was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

  • 可能是前端的 JSON 转换有问题,导致后端无法接收到正确地请求参数
  • 将请求参数通过 json.dumps() 手动转换一下 JSON 格式字符串
response = requests.post(
url="",
headers={
"Content-Type": "application/json",
},
data=json.dumps({
"key": "value",
})
)

CSDN—— 萌宅鹿同学


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK