我是这里的新手。我试图使用VRP例程来解决使用Python 3.7的your website上的示例问题,但是我遇到了一些问题。
我遵循了所有说明here,在其中说明了如何针对VR问题获取承载令牌(使用Python),并且看来工作正常。在下面的代码中,response
是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","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,headers=headers)
print(r.text)
我得到的是
{"error":"Unauthorized","error_description":"Bearer token invalid. Bearer missing or bearer value missing."}
我看到了关于StackOverflow here和here的相关问题,但是它们都没有完整的答案。 body
已从此处的网站复制。我认为该错误来自VRP的headers
。还是我在担心?我的应用程序确实需要Python代码。
在此先感谢您的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。