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)

  

posted @ 2019-05-20 16:32  zouminglan  阅读(3552)  评论(0编辑  收藏  举报