具有访问令牌的Python请求不工作

具有访问令牌的Python请求不工作,python,authentication,curl,python-requests,access-token,Python,Authentication,Curl,Python Requests,Access Token,当我使用curl在API查询下面运行时,我得到的是json响应 curl -X GET --header 'Accept: application/json' --header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c' 'https://localhost:10010/v1/machines' 但当我尝试使用python请求运行相同的查询时,我得到了拒绝访问的错误,必须提供结果代码403的授权令牌。 下面是我正在尝试的python代

当我使用curl在API查询下面运行时,我得到的是json响应

curl -X GET --header 'Accept: application/json' --header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c' 'https://localhost:10010/v1/machines'
但当我尝试使用python请求运行相同的查询时,我得到了拒绝访问的错误,必须提供结果代码403的授权令牌。 下面是我正在尝试的python代码

import requests

url = 'https://localhost:10010/v1/machines'
head = {'Authorization': 'access_token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'}

response = requests.get(url, headers=head)

print response.text
如果我在这里做错了什么,请告诉我。
谢谢

失败的原因是您传递的标头不正确

卷曲,你通过

--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'
对于请求,将遵循相同的格式,并且您必须具有:

head = {'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'}
response = requests.get(url, headers=head)

您将令牌命名为不同的东西,并且通常在每种情况下发送不同的头。@pvg请详细说明。我无法理解。请告诉我如何更正。@ChetanGomase请尝试以下操作:
{'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'}
@cᴏʟᴅsᴘᴇᴇᴅ 谢谢成功了@cgoma为后代发布了答案。如果有帮助,您可以接受:)