【问题标题】:GET request via python script with access token通过带有访问令牌的 python 脚本获取请求
【发布时间】:2018-08-31 21:15:56
【问题描述】:

我在通过 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

我相信我的脚本被服务器阻止以防止尝试报废,但我不确定。 这就是我通过 POSTMAN 运行的:

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和access token不是真实的,请勿尝试使用。 如何通过脚本而不是仅通过邮递员使其工作? 谢谢你的帮助/

【问题讨论】:

  • 'Authorization': '6ef06fee265de1fa640b6a444ba47--z'

标签: python get postman access-token


【解决方案1】:

由于您通过邮递员将令牌作为查询参数(而不是标头)发送,您可以试试这个:

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

假设您使用的 API 接受它作为查询参数而不是标头(这是我对邮递员请求的猜测)

【讨论】:

  • 刚刚尝试了您的建议,但仍然遇到同样的错误。感谢您的回复。
【解决方案2】:

如果没有真正能够测试解决方案就很难说,但我建议过去对我有用的 2 个技巧:

  1. 将“授权”改为“授权”
  2. 将“6ef06fee265de1fa640b6a444ba47--z”更改为“令牌 6ef06fee265de1fa640b6a444ba47--z”(也添加一个空格)

把它们放在一起:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 2020-04-13
    • 2020-01-15
    • 2017-12-30
    • 2019-11-30
    相关资源
    最近更新 更多