【发布时间】: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