python调用api接口案例
python调用api接口一般只需要用到requests库,非常方便import requestsimport jsonres = requests.session()headers = {'Content-Type': 'application/json'}#头文件address = "https://openapi.xiekeyun.com/openApi/delivery/getDetail
·
python调用api接口一般只需要用到requests库,非常方便
import requests
import json
res = requests.session()
headers = {'Content-Type': 'application/json'} #头文件
address = "https://openapi.xiekeyun.com/openApi/delivery/getDetail.json" #api地址
#组合的json字符串
json_str = {"commonParam":
{"appKey":"asasdasdasdasdasdas",
"version":"1.0",
"ownerCompanyCode":"asdasdasd",
"operateCompanyCode":"adasdasdasd",
"sign":sign,"timestamps":timestamps},
"body":{"erpCode":"dasdsa",
"deliveryNo":"dasdasdas"}
}
json_data = json.dumps(json_str) #转换成json数据
#print(json_data)
resp = res.post(url=address, data=json_data, headers=headers) #发送请求
print(resp.json()) #查看结果
更多推荐
已为社区贡献1条内容
所有评论(0)