Python requests.post嵌套多层json参数调用接口

#coding:utf-8
import requests,json

#第一行注解的#coding:utf-8表示可以支持中文,不然代码里面有中文会报错
url = "http://xxx"
headers = {"Content-Type":"application/json","Authorization":"Bearer token值"} 
data1 = {"key1":"value1","key2":"value2"}
data = {"params":data1}
#方法一
r = request.post(url = url,data = json.dumps(data),headers = headers)
#方法二
#r = request.post(url = url,json = data,headers = headers)
print(r)
print(r.text)
print(r.url)

  

转载于:https://www.cnblogs.com/zml-java/p/10894898.html

你可能感兴趣的:(json,python,测试)