Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过带有访问令牌的python脚本获取请求_Python_Get_Postman_Access Token - Fatal编程技术网

通过带有访问令牌的python脚本获取请求

通过带有访问令牌的python脚本获取请求,python,get,postman,access-token,Python,Get,Postman,Access Token,我在通过python使用访问令牌执行GET请求时遇到了一些困难。 出于某种原因,当我执行来自POSTMAN的请求时,我得到了预期的结果,但是,当使用python时,我得到了连接错误: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected ho

我在通过python使用访问令牌执行GET请求时遇到了一些困难。 出于某种原因,当我执行来自POSTMAN的请求时,我得到了预期的结果,但是,当使用python时,我得到了连接错误:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我相信我的脚本正在被服务器阻止,以防止尝试放弃,但我不确定。 这就是我通过邮递员运行的内容:

https://www.operation.io/web/alerts?access_token=6ef06fee265de1fa640b6a444ba47--z&envId=58739be2c25e76a202c9dd3e&folderId=active&sortBy=status
response = requests.get('https://www.operation.io/web/alerts', headers={'Authorization': 'access_token 6ef06fee265de1fa640b6a444ba47--z'})
这就是我在脚本中运行的内容:

https://www.operation.io/web/alerts?access_token=6ef06fee265de1fa640b6a444ba47--z&envId=58739be2c25e76a202c9dd3e&folderId=active&sortBy=status
response = requests.get('https://www.operation.io/web/alerts', headers={'Authorization': 'access_token 6ef06fee265de1fa640b6a444ba47--z'})
请注意,url和访问令牌不是真实的,因此请不要尝试使用。 我怎样才能通过剧本而不仅仅是邮递员来实现呢?
感谢您的帮助/

因为您通过邮递员将令牌作为查询参数(而不是标题)发送,您可以尝试以下操作:

response = requests.get('https://www.operation.io/web/alerts', params={'access_token': '6ef06fee265de1fa640b6a444ba47--z'})

假设您使用的API将其作为查询参数而不是标题接受(这是我根据邮递员请求猜测的)

如果不能够实际测试解决方案,很难判断,但我建议使用两种过去对我有效的方法:

  • 将“授权”更改为“授权”
  • 将“6ef06fee265de1fa640b6a444ba47--z”更改为“令牌6ef06fee265de1fa640b6a444ba47--z”(同时添加空格)
  • 总而言之:

    response = requests.get('https://www.operation.io/web/alerts', headers={'authorization': 'Token 6ef06fee265de1fa640b6a444ba47--z'})
    

    'Authorization':'6ef06fee265de1fa640b6a444ba47--z'
    刚刚尝试了您的建议,但仍然收到相同的错误。谢谢你的回复。