Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将运输模式限制为仅在此处行走时遇到错误GW100';香港公共交通空气污染指数_Python_Rest_Here Api - Fatal编程技术网

Python 将运输模式限制为仅在此处行走时遇到错误GW100';香港公共交通空气污染指数

Python 将运输模式限制为仅在此处行走时遇到错误GW100';香港公共交通空气污染指数,python,rest,here-api,Python,Rest,Here Api,我目前是这里公共交通API的用户,使用Python 3.7上的REST实现 我的目标是在我的学校校园的两个地点之间获得步行路线。为此,我尝试了包括“modes”参数,其值为字符串“walk”,以及API所需的其他参数 然而,我总是遇到GW100错误代码,并伴有文本“无效请求:请求在任何给定模式下都无效” 我使用的主要代码位如下,足以重现错误: import requests from datetime import datetime current_location = "1.298680,1

我目前是这里公共交通API的用户,使用Python 3.7上的REST实现

我的目标是在我的学校校园的两个地点之间获得步行路线。为此,我尝试了包括
“modes”
参数,其值为字符串
“walk”
,以及API所需的其他参数

然而,我总是遇到GW100错误代码,并伴有文本“无效请求:请求在任何给定模式下都无效”

我使用的主要代码位如下,足以重现错误:

import requests
from datetime import datetime

current_location = "1.298680,103.771922"
destination_coords = "1.29437,103.78436"
apiKey = "insert API Key"

modes = "walk"

routing_base_url = "https://transit.ls.hereapi.com/v3/route.json"

time = datetime.now().replace(microsecond = 0)
time = time.isoformat()

maximum = 1
graph = 1
maneuvers = 1

routing_params = {"apiKey": apiKey, "dep": current_location, "arr": destination_coords, "time": time, "max": maximum, "graph": graph, "maneuvers": maneuvers,"modes": modes}

raw_data = requests.get(url = routing_base_url, params = routing_params)
data = raw_data.json()

print(data)
在Python中运行代码会产生以下错误消息:

{'Res': {'serviceUrl': 'https://transit.ls.hereapi.com/transit/v3/route.json', 'Message': {'code': 'GW100', 'level': 'E', 'text': 'Invalid request: Request is not valid under any of the given schemas'}}}
该错误似乎源于
“modes”
参数。我已经检查了公共交通API指南,以确保
“模式”
的类型和格式正确:一个包含所需交通模式名称的字符串。列出了API接受的所有参数列表,同时列出了
“模式”
的运输模式列表

将其完全从
路由参数
字典中删除或将其值设置为空字符串
将导致API生成路由。然而,这条路线除了步行之外,还将使用其他交通方式,这是我不想要的


这里有什么问题吗<代码>“模式”的类型和格式已经正确,但错误似乎表明情况并非如此。

感谢您的报告。我们将要求团队在门户网站上进行更正。 看起来正确的参数是
mode=“walk”
。请在你的代码中更新这个,它应该可以工作

希望这有帮助