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())  #查看结果
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐