We use Rauth to connect to the various OAuth 1 APIs. It works fine for a single request, but trying to make 2 or more requests against a given session results in 401 unauthorized API errors.
Twitter API Example:
import requests from rauth import OAuth1Service from rauth import OAuth1Session consumer_key = {the consumer key} consumer_secret = {the consumer secret} access_token = {the access token} access_token_secret = {the access token secret} oauth_service = OAuth1Service(consumer_key = consumer_key, consumer_secret = consumer_secret) oauth_session = oauth_service.get_session(token = (access_token, access_secret)) url = 'https://api.twitter.com/1.1/statuses/home_timeline.json' params = {'include_rts': 'true'} r = oauth_session.get(url, params=params) # THIS WORKS r = oauth_session.get(url, params=params) # THIS RETURNS 401 ERROR
This happens on both Twitter and the LinkedIn API. How do we execute multiple queries against a single object OAuth1Session?
OAuth1Session
VERSIONS:Rauth == 0.5.4queries == 1.1.0
Oddly enough, if the argument is paramsnot included, several requests can be made, but after inclusion params, even if it is an empty dict, we get 401.
params
Example 1:
r = oauth_session.get(url) # THIS WORKS r = oauth_session.get(url) # THIS WORKS
Example 2:
r = oauth_session.get(url, params={}) # THIS WORKS r = oauth_session.get(url, params={}) # THIS RETURNS 401 ERROR
, session.get(..., header_auth=True) . , , Twitter, , .
session.get(..., header_auth=True)
API, , - . , , rauth , , , , , .
, rauth, Requests . , oauth_signature , , , , . , .
oauth_signature
, , , , . . , , header_auth. , - .
header_auth