mellort/reddit_api — Issue #63: HTTP Error 429: Unknown when fetching submissions
Author: mpenkov
Created: 2012-02-16 14:40:41+00:00
State: open

Hi,

I am the developer of http://rvytpl.appspot.com/. First of all, thank you for providing the Python library for the Reddit API. It's very convenient and easy to use.

I'm encountering a problem relatively frequently in this code:

```python
reddit_api = reddit.Reddit(user_agent=USER_AGENT)
subreddit = reddit_api.get_subreddit('videos').get_top(limit=100)
new_entries = { }
for rank in range(100):
if rank and (rank % 25 == 0):
logging.info('Fetched %d entries, sleeping' % rank)
time.sleep(60)
entry = subreddit.next()
new_entries[entry.id] = (rank, entry)
```

I'm trying to fetch the top 100 entries of the videos subreddit. I get this exception:

```python
HTTP Error 429: Unknown
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
handler.post(*groups)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/admin.py", line 62, in post
entry = subreddit.next()
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/__init__.py", line 231, in get_content
page_data = self.request_json(page_url, url_data=url_data)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/decorators.py", line 110, in error_checked_func
return_value = func(self, *args, **kwargs)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/__init__.py", line 265, in request_json
response = self._request(page_url, params, url_data)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/__init__.py", line 165, in _request
url_data)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/util.py", line 44, in __call__
return self._cache.setdefault(key, self.func(*args, **kwargs))
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/decorators.py", line 100, in __call__
return self.func(*args, **kwargs)
File "/base/data/home/apps/s~rvytpl/1.356858274957999053/reddit/helpers.py", line 97, in _request
response = reddit_session._opener.open(request)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 429: Unknown
```

This only happens after 25, 50 and 75 entries are fetched. I've tried increasing the sleep time, to no avail. What could be going wrong?

Cheers,
Michael