gpt4 book ai didi

python - python的开放高度api

转载 作者:行者123 更新时间:2023-12-04 08:15:04 25 4
gpt4 key购买 nike

我们可以用 open-elevation用 python ?
我尝试使用请求获取 API 并没有成功

#overpass api url
elevation_request = "https://api.open-elevation.com/api/v1/lookup\?locations\=10,10\|20,20\|41.161758,-8.583933"
elevation = requests.get(elevation_request)
data_json = elevation.json()
我们如何将这个 API 与 python 集成?

最佳答案

端点是有效的,但它们很慢或有时无响应。下面的代码是对this answer的改编处理响应状态代码和超时:

from requests import get
from pandas import json_normalize

def get_elevation(lat = None, long = None):
'''
script for returning elevation in m from lat, long
'''
if lat is None or long is None: return None

query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={_lat},{_long}')

# Request with a timeout for slow responses
r = get(query, timeout = 20)

# Only get the json response in case of 200 or 201
if r.status_code == 200 or r.status_code == 201:
elevation = json_normalize(r.json(), 'results')['elevation'].values[0]
else:
elevation = None
return elevation

关于python - python的开放高度api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65748099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com