我想调用curl函数python脚本来调用API。该怎么做。
我从航站楼开出了电话,情况很好。
curl --header "Authorization: Api-Key ABCD1234" https://api.lat.com/western/v1/forecasts?locodes=PLWRE,DEHLI
{"results":[{"place":{"type":"locode","value":"PLWRO"},"measures":[{"ts":1571896800000,"t2m":10.72,"t_min":10.53,"t_max":11.99,"wspd":8,"dir":"SE","wgust":12,"rh2m":87,"prsmsl":1012,"skcover":"clear","precip":0.0,"snowd":0,"thunderstorm":"N","fog":"H"}]},{"place":{"type":"locode","value":"DEHAM"},"measures":[{"ts":1571896800000,"t2m":10.79,"t_min":10.3,"t_max":10.9,"wspd":13,"dir":"ESE","wgust":31,"rh2m":97,"prsmsl":1008,"skcover":"partly_cloudy","precip":0.0,"snowd":0,"thunderstorm":"N","fog":"H"}]}]}sh-4.2$
这怎么办?
答案 0 :(得分:1)
您可以使用requests
库进行cURL调用。
import requests
url = "https://api.lat.com/western/v1/forecasts?locodes=PLWRE,DEHLI"
headers = {
"Authorization": "Api-Key ABCD1234"
}
response = requests.get(url=url, headers=headers)
您可以使用response.json()
获得JSON格式的响应。
答案 1 :(得分:0)
我建议此资源: https://curl.trillworks.com/
它只是利用请求模块将curl语句转换为参数。