oauth_hook, imgur and requests error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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