python - 如果发生错误以使用不同的 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)
有没有办法做到这一点?任何提示表示赞赏!
解决方案
推荐阅读
- python - conn.recv python套接字上的无限加载
- dataframe - 在点分隔符上拆分列
- macos - 在 Mac 上将 Xerces 库构建为通用二进制文件的问题
- angular - 使用共享服务在 Angular 中返回空的兄弟组件之间共享数据
- c - 为什么我的 C 结构在输入中没有得到任何数据?
- google-cloud-platform - 附加现有磁盘时实例组不启动
- java - 我可以在 Android 数据绑定中使用 ObservableArrayMap 计算 ObservableInt 吗?
- python - 针对超大型数据库优化 SPARQL 查询
- python-3.x - Python threding 请求计数
- python - 将结果保存为 pyspark 多输出循环中的数据帧