通过带有访问令牌的python脚本获取请求
我在通过python使用访问令牌执行GET请求时遇到了一些困难。 出于某种原因,当我执行来自POSTMAN的请求时,我得到了预期的结果,但是,当使用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
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将其作为查询参数而不是标题接受(这是我根据邮递员请求猜测的)如果不能够实际测试解决方案,很难判断,但我建议使用两种过去对我有效的方法:
response = requests.get('https://www.operation.io/web/alerts', headers={'authorization': 'Token 6ef06fee265de1fa640b6a444ba47--z'})
'Authorization':'6ef06fee265de1fa640b6a444ba47--z'
刚刚尝试了您的建议,但仍然收到相同的错误。谢谢你的回复。