voussoir / timesearch

The subreddit archiver
BSD 3-Clause "New" or "Revised" License
171 stars 7 forks source link

404 for https://api.pushshift.io/meta #18

Closed RaedShabbir closed 1 year ago

RaedShabbir commented 1 year ago

Relevant https://www.reddit.com/r/pushshift/comments/zlryw1/ive_been_getting_response_status_code_404_since/

RaedShabbir commented 1 year ago

Update:

https://www.reddit.com/r/pushshift/comments/zhzaea/the_day_has_finally_arrived_pushshift_api_move/

So i think this is to be expected for a bit.

RaedShabbir commented 1 year ago

Update requires minor change in pushshift.py, "sort"->"order" and "sort_type"->"sort". Will share a PR once I have it fully working.

rickcecil commented 1 year ago

@RaedShabbir Curious the status on your changes?

I am sorting through the required changes myself at the moment. It sounds like https://api.pushshift.io/meta will no longer be available. Or did I misread? Do you know if there is a new URL? Or does the def _initialize_ratelimiter() need to be rewritten?

rickcecil commented 1 year ago

In addition to the sort and order changes above, I had to update def _initialize_ratelimiter(). Not sure if this is the best solution or not. I ended up removing most of the code in def _initialize_ratelimiter(), including the url call to https://api.pushshift.io/meta.

The new def _initialize_ratelimiter() looks like this:

def _initialize_ratelimiter(): global ratelimit ratelimit = ratelimiter.Ratelimiter(allowance=120, period=60)

It seems to be working.

I cannot figure out how to get a dynamic rate limit from pushshift itself.

voussoir commented 1 year ago

Hi, thanks for bringing this to my attention. I generally prefer to maintain authorship instead of doing pull requests.

If /meta is gone for good, we don't need the initialize function at all any more -- we'll just define ratelimit at the top of the file with a constant value.

Sounds like we're doing this:

 DEFAULT_PARAMS = {
     'size': 1000,
-    'sort': 'asc',
-    'sort_type': 'created_utc',
+    'order': 'asc',
+    'sort': 'created_utc',
 }
 session.headers.update({'User-Agent': useragent})
+ratelimit = ratelimiter.Ratelimiter(allowance=120, period=60)

 class DummyObject:
-def _initialize_ratelimiter():
-    global ratelimit
-    if ratelimit is not None:
-        return
-    log.debug('Initializing pushshift ratelimiter.')
-    url = 'https://api.pushshift.io/meta'
-    response = session.get(url)
-    response.raise_for_status()
-    response = response.json()
-    limit = response['server_ratelimit_per_minute']
-    log.debug('Pushshift ratelimit is %d requests per minute.', limit)
-    ratelimit = ratelimiter.Ratelimiter(allowance=limit, period=60)

 def get(url, params=None):
-    _initialize_ratelimiter()
     if not url.startswith('https://'):
         url = API_URL + url.lstrip('/')

But I'm getting 500-level errors from all of api.pushshift.io so I can't test or read their new docs just yet.

rickcecil commented 1 year ago

I made the changes and tested them and everything is working for me. Thanks @voussoir and @RaedShabbir! I am still getting 524 errors, but it sounds like these have something to do with the move to the COLO and they are working on resolving them. That being said, given enough time, all of my scripts are running. Thanks!

voussoir commented 1 year ago

Closed by 2c0ae7291a752f90e8d40bce5f6a43afb428f258, thank you