首页 > 解决方案 > 如果发生错误以使用不同的 URL,则 Python 异常 - openrouteservice

问题描述

因此,我编写了一个脚本来从 ORS-API 请求路由,但使用 ORS 的本地主机实例 - 问题是我无法托管整个欧洲,但在我的本地托管区域内没有坐标。如果发生超出范围的错误以使用 ORS 的全局实例而不是我的本地托管的实例,是否有例外的方法?

我编写的脚本使用以下代码来拉取请求:

body = {"coordinates":coords,"extra_info":["waycategory"]}

headers = {
    'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
    'Content-Type': 'application/geo+json; charset=utf-8'
}
call = requests.post('http://127.0.0.1:8080/ors/v2/directions/driving-hgv/geojson', json=body, headers=headers)

weiter = call.text

data = json.loads(weiter)

现在我想要一个例外,比如使用:

call = requests.post('http://openrouteservice.org/ors/v2/directions/driving-hgv/geojson', json=body, headers=headers)

#if out of reach-error (coordinates not in the local hosted instance)

有没有办法做到这一点?任何提示表示赞赏!

标签: pythonexceptionopenrouteservice

解决方案


推荐阅读