VRP Python 请求
VRP Python request
我是 HERE 的新手。我试图使用 VRP 例程来解决 your website 上使用 Python 3.7 的示例问题,但我遇到了一些问题。
我遵循了所有说明 here, where it is explained how to obtain the bearer token (using Python) for the VR problem and it seems that this worked fine. In the code below, response
is the final output of the blog page,它包含生成的不记名令牌。如您所见,我对变量 headers
(对于 VRP 例程)尝试了不同的方法。
...
response = requests.post(url, data=body, headers=headers)
access_token = response.json()['access_token']
headers = {'Content-Type' : 'application/json',
# 'Authorization' : 'Bearer"'+response.json()['access_token']+'"'
# 'Authorization' : response.json()['access_token']
# 'Authorization' : 'Bearer<'+response.json()['access_token']+'>'
# 'Authorization' : 'Bearer'+response.json()['access_token']
'Authorization' : 'Bearer="'+access_token+'"'
# 'Authorization' : 'bearer="'+access_token+'"'
}
URL = "https://vrp.api.here.com/v1/problems"
body = {
"id": "myProblem",
"plan": {
"jobs": [
{
"id": "myJob",
"places": {
"delivery": {
"location": {"lat": 52.46642, "lng": 13.28124},
"times": [["2020-08-13T10:00:00.000Z","2020-08-13T12:00:00.000Z"]],
"duration": 180
}
},
"demand": [1]
}
]
},
"fleet": {
"types": [
{
"id": "myVehicle",
"profile": "car",
"costs": {
"distance": 0.0002,
"time": 0.004806,
"fixed": 22
},
"shifts": [{
"start": {
"time": "2020-08-13T09:00:00Z",
"location": {"lat": 52.52568, "lng": 13.45345}
},
"end": {
"time": "2020-08-13T18:00:00Z",
"location": {"lat": 52.52568, "lng": 13.45345}
}
}],
"capacity": [10],
"amount": 1
}
],
"profiles": [{
"name": "normal_car",
"type": "car"
}]
}
}
# sending get request and saving the response as response object
r = requests.post(URL, data=body, headers=headers)
print(r.text)
我得到的是
{"error":"Unauthorized","error_description":"Bearer token invalid. Bearer missing or bearer value missing."}
我在 Whosebug here and here 上看到有相关问题,但其中 none 有完整的答案。 body
已从 HERE 网站复制。我认为错误来自 VRP 的 headers
。还是我在工作?我的应用程序真的需要 Python 代码。
在此先感谢您的帮助。
免费增值服务无法访问旅游计划API,并且您的代码中存在不正确的授权 header 格式,您可以更正它,它应该可以工作:
headers = {'Content-Type' : 'application/json',
'Authorization' : 'Bearer ' + access_token
}
一旦成功,您将收到 403 禁止错误,因为免费增值计划无法访问此 API。
{"error":"Forbidden","error_description":"These credentials do not authorize access"}
您可以随时在 Project Details page. If you'd like to upgrade to a plan that’s not offered on developer.here.com, please contact us 上升级您的计划。
我是 HERE 的新手。我试图使用 VRP 例程来解决 your website 上使用 Python 3.7 的示例问题,但我遇到了一些问题。
我遵循了所有说明 here, where it is explained how to obtain the bearer token (using Python) for the VR problem and it seems that this worked fine. In the code below, response
is the final output of the blog page,它包含生成的不记名令牌。如您所见,我对变量 headers
(对于 VRP 例程)尝试了不同的方法。
...
response = requests.post(url, data=body, headers=headers)
access_token = response.json()['access_token']
headers = {'Content-Type' : 'application/json',
# 'Authorization' : 'Bearer"'+response.json()['access_token']+'"'
# 'Authorization' : response.json()['access_token']
# 'Authorization' : 'Bearer<'+response.json()['access_token']+'>'
# 'Authorization' : 'Bearer'+response.json()['access_token']
'Authorization' : 'Bearer="'+access_token+'"'
# 'Authorization' : 'bearer="'+access_token+'"'
}
URL = "https://vrp.api.here.com/v1/problems"
body = {
"id": "myProblem",
"plan": {
"jobs": [
{
"id": "myJob",
"places": {
"delivery": {
"location": {"lat": 52.46642, "lng": 13.28124},
"times": [["2020-08-13T10:00:00.000Z","2020-08-13T12:00:00.000Z"]],
"duration": 180
}
},
"demand": [1]
}
]
},
"fleet": {
"types": [
{
"id": "myVehicle",
"profile": "car",
"costs": {
"distance": 0.0002,
"time": 0.004806,
"fixed": 22
},
"shifts": [{
"start": {
"time": "2020-08-13T09:00:00Z",
"location": {"lat": 52.52568, "lng": 13.45345}
},
"end": {
"time": "2020-08-13T18:00:00Z",
"location": {"lat": 52.52568, "lng": 13.45345}
}
}],
"capacity": [10],
"amount": 1
}
],
"profiles": [{
"name": "normal_car",
"type": "car"
}]
}
}
# sending get request and saving the response as response object
r = requests.post(URL, data=body, headers=headers)
print(r.text)
我得到的是
{"error":"Unauthorized","error_description":"Bearer token invalid. Bearer missing or bearer value missing."}
我在 Whosebug here and here 上看到有相关问题,但其中 none 有完整的答案。 body
已从 HERE 网站复制。我认为错误来自 VRP 的 headers
。还是我在工作?我的应用程序真的需要 Python 代码。
在此先感谢您的帮助。
免费增值服务无法访问旅游计划API,并且您的代码中存在不正确的授权 header 格式,您可以更正它,它应该可以工作:
headers = {'Content-Type' : 'application/json',
'Authorization' : 'Bearer ' + access_token
}
一旦成功,您将收到 403 禁止错误,因为免费增值计划无法访问此 API。
{"error":"Forbidden","error_description":"These credentials do not authorize access"}
您可以随时在 Project Details page. If you'd like to upgrade to a plan that’s not offered on developer.here.com, please contact us 上升级您的计划。