【问题标题】:Why am I receiving a code that I am not authorized (401) when I am giving my access token?为什么我在提供访问令牌时收到未经授权的代码 (401)?
【发布时间】:2019-05-21 14:59:00
【问题描述】:

为什么我在此处尝试从 HOST 获取信息时收到 401 错误?

我正在使用我的令牌,这不应该给我完全访问权限吗?

   HOST = "https://api.surveymonkey.com/v3/surveys"


   r= requests.get(HOST, api_token)
   r.text
   print r

【问题讨论】:

    标签: python rest python-requests surveymonkey


    【解决方案1】:

    您以错误的方式传递 api_token。阅读网站文档,了解他们如何传递令牌是解决您问题的正确方法。

    在一般情况下我们会这样做:

    requests.get(HOST, auth=(user,api_token))
    

    但有时我们可以直接将令牌传递到标头中:

    requests.get(HOST, headers={'Authorization': "Bearer {}".format(api_token)})
    requests.get(HOST, headers={'Authorization': api_token})
    

    阅读Python requests library how to pass Authorization header with single token了解更多关于如何直接传递令牌的信息。

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2016-09-11
        • 2019-11-02
        • 1970-01-01
        • 2017-07-06
        • 2020-03-06
        • 1970-01-01
        • 1970-01-01
        • 2017-06-11
        • 1970-01-01
        相关资源
        最近更新 更多