“PLAINTEXT”oauth请求

时间:2016-03-08 09:34:07

标签: python

尝试将method = plaintext用于oauth。我很难找到任何例子,或者之前关于纯文本的问题。

对于那些不知道它是什么但想要帮助的人,this document provides a nice overview

import requests
from requests_oauthlib import OAuth1
from rauth import OAuth1Session, OAuth1Service

myheaders = {'Authorization': 'OAuth ,oauth_consumer_key="5C82CC6BC7C6472154FBC9CAB24A29A2",oauth_signature_method="PLAINTEXT", oauth_signature="F9D6B42C41A618C273AB501F2F2613F1"'}
url = 'https://secure.tmsandbox.co.nz/Oauth/RequestToken?scope=MyTradeMeRead,MyTradeMeWrite '
r = requests.get(url, params=myheaders)
print(r)

这给了我< Response [400]>

任何想法为什么? (给予工作的关键但是假的)

1 个答案:

答案 0 :(得分:1)

以这种方式打印内容时:

>>>print (r.content)
The oauth_consumer_key parameter is required.

您有一些语法错误,您的myheaders字典格式不正确,请按以下方式修复:

import requests
from requests_oauthlib import OAuth1
from rauth import OAuth1Session, OAuth1Service

myheaders = {'Authorization':'OAuth',
             'oauth_consumer_key':'5C82CC6BC7C6472154FBC9CAB24A29A2',
             'oauth_signature_method': 'PLAINTEXT',
             'oauth_signature': 'F9D6B42C41A618C273AB501F2F2613F1'}
url = 'https://secure.tmsandbox.co.nz/Oauth/RequestToken?scope=MyTradeMeRead,MyTradeMeWrite '
r = requests.get(url, params=myheaders)
print(r.status_code)
print(r.content)

>>401
>>Invalid PLAINTEXT signature.

您似乎还有另一个错误,我无法弄清楚