Skip to content

Instantly share code, notes, and snippets.

@ollieglass
Created May 19, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ollieglass/2732412 to your computer and use it in GitHub Desktop.
Save ollieglass/2732412 to your computer and use it in GitHub Desktop.
oauth_hook, imgur and requests error
import requests
import urlparse
from oauth_hook import OAuthHook
# consumer key + secret
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
# get access token, create client
client = requests.session(
hooks={'pre_request': OAuthHook(consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)}
)
response = client.post('https://api.imgur.com/oauth/request_token')
qs = urlparse.parse_qs(response.text)
oauth_hook = OAuthHook(qs['oauth_token'], qs['oauth_token_secret'], CONSUMER_KEY, CONSUMER_SECRET)
client = requests.session(hooks={'pre_request': oauth_hook})
# request imgur stats
print 1
r = client.get("http://api.imgur.com/2/stats.json", data={"view":"all"})
print 2
# print r.text
1
Traceback (most recent call last):
File "/Users/ollieglass/.virtualenvs/carbonator/lib/python2.7/site-packages/requests/hooks.py", line 47, in dispatch_hook
hook_data = hook(hook_data) or hook_data
File "/Users/ollieglass/.virtualenvs/carbonator/lib/python2.7/site-packages/oauth_hook/hook.py", line 187, in __call__
request.oauth_params['oauth_signature'] = self.signature.sign(request, self.consumer, self.token)
File "/Users/ollieglass/.virtualenvs/carbonator/lib/python2.7/site-packages/oauth_hook/auth.py", line 65, in sign
key, raw = self.signing_base(request, consumer, token)
File "/Users/ollieglass/.virtualenvs/carbonator/lib/python2.7/site-packages/oauth_hook/hook.py", line 26, in signing_base
key += escape(token.secret)
File "/Users/ollieglass/.virtualenvs/carbonator/lib/python2.7/site-packages/oauth_hook/auth.py", line 14, in <lambda>
escape = lambda url: urllib.quote(to_utf8(url), safe='~')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1248, in quote
if not s.rstrip(safe):
AttributeError: 'list' object has no attribute 'rstrip'
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment