小编ama*_*r19的帖子

Python中使用JSON数据的HTTP PUT请求

我想使用JSON数据在Python中发出PUT请求

data = [{"$TestKey": 4},{"$TestKey": 5}]
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?

import requests
import json

url = 'http://localhost:6061/data/'

data = '[{"$key": 8},{"$key": 7}]'

headers = {"Content-Type": "application/json"}

response = requests.put(url, data=json.dumps(data), headers=headers)

res = response.json()

print(res)
Run Code Online (Sandbox Code Playgroud)

得到这个错误

requests.exceptions.InvalidHeader: Value for header {data: [{'$key': 4}, {'$key': 5}]} must be of type str or bytes, not <class 'list'>

python json http put

6
推荐指数
2
解决办法
6654
查看次数

标签 统计

http ×1

json ×1

put ×1

python ×1