HERE-API 获取序列优化不 return
HERE-API get for sequence optimization does not return
我正在尝试使用此处-api 和 findsequence.json-API 优化某些 waypoints 的序列。
我的代码如下所示:
#! /usr/bin/python
# coding: utf8
from requests import Request, Session
import requests
class HereConector:
app_id = "get_your_own_app_ip"
app_code = "get_your_own_app_code"
sequence_url = "https://wse.cit.api.here.com/2/findsequence.json"
container_locations = [(u'Hamburg', [53.551086, 9.993682]), (u'Munich', [48.13715, 11.576124]), (u'Berlin', [52.520008, 13.404954]), (u'D', [51.514244, 7.468429])]
def __init__(self):
pass
# small proof that the process can work
def get_demo_route(self):
url = "https://route.api.here.com/routing/7.2/calculateroute.json"
# app_data = {"app_id": self.app_id, "app_code": self.app_code}
app_data = {"waypoint0": "52.5,13.4", "waypoint1":"52.5,13.45", "mode": "fastest;car;traffic:disabled"}
app_data['app_id'] = self.app_id
app_data['app_code'] = self.app_code
print (requests.get(url, app_data).json())
def loc_to_waypoint(self, location):
return str(location[1][0]) + ',' + str(location[1][1])
def find_sequence(self):
app_data = {"app_id": self.app_id, "app_code": self.app_code}
app_data['start'] = self.loc_to_waypoint(self.container_locations[0])
for i, cl in enumerate(self.container_locations):
if i == 0:
continue
app_data['destination' + str(i)] = self.loc_to_waypoint(cl)
if i == 10:
break
app_data['end'] = self.loc_to_waypoint(self.container_locations[-1])
app_data['mode'] = 'truck;fastest'
s = Session()
req = Request('GET', url=self.sequence_url, params=app_data).prepare()
# This URL can be copy/pasted into a browser and returns an optimized sequence
print (req.url)
# this call blocks
r = s.send(req)
# this call also blocks
# r = requests.get(self.sequence_url, app_data)
print (r.json())
if __name__ == "__main__":
hc = HereConector()
hc.get_demo_route()
hc.find_sequence()
如果我将生成的 URL 复制到我的浏览器中,我会立即获得优化的路线(处理时间 < 200 毫秒),因此 url 和参数应该是正确的。但是,对 s.send(或 requests.get(self.map_view_url,app_data))的调用会阻塞。 (其他调用例如让地图与请求完美配合)。
这也是我对请求库的第一次实验,所以我不知道如何进一步调试。
更新:代码显示 python2.7 和 python3
的相同行为
我们尝试执行您的上述代码并使用 s.send 和 requests.get 调用查看以下响应。所以问题似乎与代码无关。您能否检查您的凭据以及您可以使用它提出的相应请求数量。可能是您超出了配额,因此请求被阻止。尝试使用不同的应用程序 ID 和代码。
{'results': [{'waypoints': [{'id': 'start', 'lat': 53.551086, 'lng': 9.993682, 'sequence': 0, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination2', 'lat': 52.520008, 'lng': 13.404954, 'sequence': 1, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination1', 'lat': 48.13715, 'lng': 11.576124, 'sequence': 2, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination3', 'lat': 51.514244, 'lng': 7.468429, 'sequence': 3, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'end', 'lat': 51.514244, 'lng': 7.468429, 'sequence': 4, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}], 'distance': '1484517', 'time': '68916', 'interconnections': [{'fromWaypoint': 'start', 'toWaypoint': 'destination2', 'distance': 289082.0, 'time': 13845.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination2', 'toWaypoint': 'destination1', 'distance': 591003.0, 'time': 27227.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination1', 'toWaypoint': 'destination3', 'distance': 604430.0, 'time': 27844.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination3', 'toWaypoint': 'end', 'distance': 2.0, 'time': 0.0, 'rest': 0.0, 'waiting': 0.0}], 'description': 'Targeted best time; without traffic', 'timeBreakdown': {'driving': 68916, 'service': 0, 'rest': 0, 'waiting': 0}}], 'errors': [], 'processingTimeDesc': '940ms', 'responseCode': '200', 'warnings': None, 'requestId': None}
我正在尝试使用此处-api 和 findsequence.json-API 优化某些 waypoints 的序列。
我的代码如下所示:
#! /usr/bin/python
# coding: utf8
from requests import Request, Session
import requests
class HereConector:
app_id = "get_your_own_app_ip"
app_code = "get_your_own_app_code"
sequence_url = "https://wse.cit.api.here.com/2/findsequence.json"
container_locations = [(u'Hamburg', [53.551086, 9.993682]), (u'Munich', [48.13715, 11.576124]), (u'Berlin', [52.520008, 13.404954]), (u'D', [51.514244, 7.468429])]
def __init__(self):
pass
# small proof that the process can work
def get_demo_route(self):
url = "https://route.api.here.com/routing/7.2/calculateroute.json"
# app_data = {"app_id": self.app_id, "app_code": self.app_code}
app_data = {"waypoint0": "52.5,13.4", "waypoint1":"52.5,13.45", "mode": "fastest;car;traffic:disabled"}
app_data['app_id'] = self.app_id
app_data['app_code'] = self.app_code
print (requests.get(url, app_data).json())
def loc_to_waypoint(self, location):
return str(location[1][0]) + ',' + str(location[1][1])
def find_sequence(self):
app_data = {"app_id": self.app_id, "app_code": self.app_code}
app_data['start'] = self.loc_to_waypoint(self.container_locations[0])
for i, cl in enumerate(self.container_locations):
if i == 0:
continue
app_data['destination' + str(i)] = self.loc_to_waypoint(cl)
if i == 10:
break
app_data['end'] = self.loc_to_waypoint(self.container_locations[-1])
app_data['mode'] = 'truck;fastest'
s = Session()
req = Request('GET', url=self.sequence_url, params=app_data).prepare()
# This URL can be copy/pasted into a browser and returns an optimized sequence
print (req.url)
# this call blocks
r = s.send(req)
# this call also blocks
# r = requests.get(self.sequence_url, app_data)
print (r.json())
if __name__ == "__main__":
hc = HereConector()
hc.get_demo_route()
hc.find_sequence()
如果我将生成的 URL 复制到我的浏览器中,我会立即获得优化的路线(处理时间 < 200 毫秒),因此 url 和参数应该是正确的。但是,对 s.send(或 requests.get(self.map_view_url,app_data))的调用会阻塞。 (其他调用例如让地图与请求完美配合)。
这也是我对请求库的第一次实验,所以我不知道如何进一步调试。
更新:代码显示 python2.7 和 python3
的相同行为我们尝试执行您的上述代码并使用 s.send 和 requests.get 调用查看以下响应。所以问题似乎与代码无关。您能否检查您的凭据以及您可以使用它提出的相应请求数量。可能是您超出了配额,因此请求被阻止。尝试使用不同的应用程序 ID 和代码。
{'results': [{'waypoints': [{'id': 'start', 'lat': 53.551086, 'lng': 9.993682, 'sequence': 0, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination2', 'lat': 52.520008, 'lng': 13.404954, 'sequence': 1, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination1', 'lat': 48.13715, 'lng': 11.576124, 'sequence': 2, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'destination3', 'lat': 51.514244, 'lng': 7.468429, 'sequence': 3, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}, {'id': 'end', 'lat': 51.514244, 'lng': 7.468429, 'sequence': 4, 'estimatedArrival': None, 'estimatedDeparture': None, 'fulfilledConstraints': []}], 'distance': '1484517', 'time': '68916', 'interconnections': [{'fromWaypoint': 'start', 'toWaypoint': 'destination2', 'distance': 289082.0, 'time': 13845.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination2', 'toWaypoint': 'destination1', 'distance': 591003.0, 'time': 27227.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination1', 'toWaypoint': 'destination3', 'distance': 604430.0, 'time': 27844.0, 'rest': 0.0, 'waiting': 0.0}, {'fromWaypoint': 'destination3', 'toWaypoint': 'end', 'distance': 2.0, 'time': 0.0, 'rest': 0.0, 'waiting': 0.0}], 'description': 'Targeted best time; without traffic', 'timeBreakdown': {'driving': 68916, 'service': 0, 'rest': 0, 'waiting': 0}}], 'errors': [], 'processingTimeDesc': '940ms', 'responseCode': '200', 'warnings': None, 'requestId': None}