VRP Python请求

我是这里的新手。我试图使用VRP例程来解决使用Python 3.7的your website上的示例问题,但是我遇到了一些问题。

我遵循了所有说明here,在其中说明了如何针对VR问题获取承载令牌(使用Python),并且看来工作正常。在下面的代码中,responseblog 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 herehere的相关问题,但是它们都没有完整的答案。 body已从此处的网站复制。我认为该错误来自VRP的headers。还是我在担心?我的应用程序确实需要Python代码。

在此先感谢您的帮助。

相关文章

本文适合有 Python 基础的小伙伴进阶学习 作者:pwwang 一、...
前言 目前有个python应用需要在容器镜像内拉取git私有仓库的...
前言 当网络不稳定或应用页面加载有问题,可以设置等待,避免...
前言 map()、reduce()、filter()是python的三个高阶函数。所...
入门使用 # 示例代码 warframe = [&quot;saryn&quot...
前言 功能描述:批量重命名指定目录下的文件,文件名加前缀,...