使用requests模块put和post json数据时,需要使用json模块的dumps函数,如下:

import requests
import json

url = "http://localhost:9900"

data = {
    "first_name":"John",
    "last_name":"Smith",
    "age":18
}

response = requests.put(url+"/test/1",data=json.dumps(data))
print(response.text)