musss
musss

Reputation: 125

"PLAINTEXT" oauth request

Trying to use method = plaintext for an oauth. I'm having a tough time finding any examples, or previous questions on plain text.

For those who don't know what it is but would like to help, 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)

This gives me < Response [400]>

Any ideas why? (keys given work but are dummy)

Upvotes: 1

Views: 303

Answers (1)

mvelay
mvelay

Reputation: 1520

When printing content this way:

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

you have some syntax errors, your myheaders dictionary is not well formatted, fix it this way:

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.

It seems you have another error that I can't figure out

Upvotes: 1

Related Questions