【发布时间】:2013-07-22 08:05:22
【问题描述】:
当我在 EC2 Linux 服务器实例(运行 Ubuntu 13.04)上运行我正在处理的脚本时,我正在努力获得 OAuth2 授权。相关的sn-p是:
with open('creds.txt') as f:
creds = {}
for line in f:
creds[line.split(',')[0]] = line.split(',')[1].rstrip('\n')
self.client_id = creds['client_id']
self.client_secret = creds['client_secret']
self.username = creds['username']
self.password = creds['password'])
token_response = requests.post(
"https://example.com/oauth2/access_token/",
data={
"grant_type": "password",
"client_id": self.client_id,
"client_secret": self.client_secret,
"username": self.username,
"password": self.password,
"scope": "read+write"}).json()
它在我的家用计算机(运行 Windows 7)上运行良好,只是当我尝试远程运行它时却不行:{u'error': u'invalid_client'}。
我已尝试设置新的客户端 ID 和密码,但仍然得到相同的响应。
- 为什么它在远程服务器上的工作方式与在我自己的机器上不同?
-
在哪台机器上创建应用程序是否重要(见评论)?- 我通过在两种环境中使用CURL成功进行身份验证消除了这种可能性。
我现在唯一能想到的可能是请求库在 Ubuntu 上处理 POST 请求的方式不同。有人知道是不是这样吗?
【问题讨论】:
-
This answer 似乎是相关的,因为它表明客户端 ID 关心它是在什么操作系统上生成的。不过,我在the docs 中找不到任何可以确认的信息。
标签: python python-2.7 oauth-2.0 eol