我想使用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'>