From 78bd08e5c339c0b0bcf55661b05ef0ed2ef717ed Mon Sep 17 00:00:00 2001 From: davidhubbard Date: Tue, 1 Jul 2014 00:23:20 -0600 Subject: [PATCH 1/2] override request() to fix "429 Too Many Requests" override request so User-Agent does not get lumped in with all urllib hits on reddit (results in "429 Too Many Requests") http://stackoverflow.com/questions/13213048/urllib2-http-error-429 --- social/backends/reddit.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/social/backends/reddit.py b/social/backends/reddit.py index 96be7f811..00afba194 100644 --- a/social/backends/reddit.py +++ b/social/backends/reddit.py @@ -49,3 +49,13 @@ def refresh_token_params(self, token, redirect_uri=None, *args, **kwargs): params = super(RedditOAuth2, self).refresh_token_params(token) params['redirect_uri'] = self.redirect_uri or redirect_uri return params + + def request(self, url, method='GET', *args, **kwargs): + """override request so User-Agent does not get lumped in with all urllib hits on reddit (results in "429 Too Many Requests") + http://stackoverflow.com/questions/13213048/urllib2-http-error-429""" + ua = 'python-social-auth-' + sys.modules['social'].__version__ + if 'headers' not in kwargs: + kwargs.set('headers', {}) + if 'User-Agent' not in kwargs['headers']: + kwargs['headers']['User-Agent'] = ua + return super(RedditOAuth2, self).request(url, method, *args, **kwargs) From d8dade7f1032a9618bf937f8e70263f2f5e858fc Mon Sep 17 00:00:00 2001 From: davidhubbard Date: Tue, 1 Jul 2014 00:59:17 -0600 Subject: [PATCH 2/2] fix PR #317 --- social/backends/reddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/social/backends/reddit.py b/social/backends/reddit.py index 00afba194..d7eaa1219 100644 --- a/social/backends/reddit.py +++ b/social/backends/reddit.py @@ -5,6 +5,7 @@ import base64 from social.backends.oauth import BaseOAuth2 +import sys class RedditOAuth2(BaseOAuth2):