【问题标题】:Python Requests OAuth2Session() passing multiple scope argumentsPython 请求 OAuth2Session() 传递多个范围参数
【发布时间】:2018-08-21 05:20:20
【问题描述】:

我已成功授权使用“data_read”作为范围的 API 连接,但是在将多个范围参数(“data_read”和“data_write”)传递到 OAuth2Session() 函数时遇到问题。

多个作用域的参数需要传入URL字符串

https://api.website.com/oauth20/authorize?response_type=code&client_id=123456&redirect_uri=https...&scope=data_read&scope=data_write...

我尝试过使用逗号分隔的列表:

scope=["data_read", "data_write"]

导致:

https://api.website.com/oauth20/authorize?response_type=code&client_id=123456&redirect_uri=https...&scope=data_read+data_write

我也尝试过在字典中传递范围列表:

dict_scope = {'scope':["data_read", "data_write"]}

这会导致错误:

ValueError: Invalid scope ({'scope': ['data_read', 'data_write']}), must be string, tuple, set, or list.

我在这里查看了请求文档:

http://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls

这里:

http://requests-oauthlib.readthedocs.io/en/latest/api.html#oauth-2-0-session

这里还有 OAuth2 示例:

http://requests-oauthlib.readthedocs.io/en/latest/examples/examples.html#examples

任何想法或建议将不胜感激

【问题讨论】:

    标签: python oauth-2.0 python-requests


    【解决方案1】:

    遇到了同样的问题。传递由多个作用域参数组成的以空格分隔的字符串,如下所述。

    scope = "data_read data_write"
    

    【讨论】:

      猜你喜欢
      • 2011-02-19
      • 2015-04-21
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 2016-01-25
      • 2014-12-09
      • 2012-07-22
      • 2011-07-05
      相关资源
      最近更新 更多