Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么OAuth2身份验证可以在家庭计算机上工作,而不能在服务器上工作?_Python_Python 2.7_Oauth 2.0_Eol - Fatal编程技术网

Python 为什么OAuth2身份验证可以在家庭计算机上工作,而不能在服务器上工作?

Python 为什么OAuth2身份验证可以在家庭计算机上工作,而不能在服务器上工作?,python,python-2.7,oauth-2.0,eol,Python,Python 2.7,Oauth 2.0,Eol,当我在EC2Linux服务器实例(运行Ubuntu13.04)上运行一个脚本时,我正在努力获得OAuth2授权来处理它。相关的代码片段是: 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_

当我在EC2Linux服务器实例(运行Ubuntu13.04)上运行一个脚本时,我正在努力获得OAuth2授权来处理它。相关的代码片段是:

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()
它在我的家用电脑(运行Windows7)上运行良好,只是当我尝试远程运行它时,我发现:
{u'error':u'invalid_client'}

我尝试设置新的客户端ID和密码,但仍然得到相同的响应

  • 为什么它在远程服务器上的工作方式与在我自己的机器上的不同
  • 应用程序是在哪台机器上创建的(请参见注释)重要吗我通过在两种环境中成功地使用
    CURL
    进行身份验证,消除了这种可能性

我现在唯一能想到的是,也许请求库在Ubuntu上处理POST请求的方式有所不同。有人知道情况是否如此吗?

当Nix和Windows环境之间存在差异时,这可能是我应该想到的第一件事:

始终检查下线字符

问题是,当从凭据文件中获取用户名、密码等时,我使用
string.rstrip('\n')
剥离换行符,因此在Unix环境中,会留下一个
\r
回车符,然后将其作为
POST
请求的一部分传递

在这两种环境中都有效的方法是使用
string.rstrip()
,它去除所有尾随空格和行尾字符。

似乎与此相关,因为它表明客户端ID关心它是在什么操作系统上生成的。不过,我找不到任何东西来证实这一点。