pubg-python: RateLimitError Auto-Handling

Firstly, thank you for your great work! In practice, I find myself scratching my head when Iโ€™m constantly getting RateLimitError when Iโ€™m collecting data for my friends, due to the 5 request/min limitation. Therefore, Iโ€™m suggesting a feature which wraps around the requests using some structure like the following:

cont = False
while not cont:
    try:
        # make the request
        
       cont = True
   except pubg_python.exceptions.RateLimitError:
        time.sleep(60)

This has the disadvantage of making the return time of the call very unpredictable. However, we could warn the users about it and let them choose which to use.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Awesome. Glad this will make your life easier. ๐Ÿ˜ƒ Cheers!

@Klamath233 | @glmn

Take a look at https://github.com/ramonsaraiva/pubg-python/pull/77 Docs are available in https://github.com/ramonsaraiva/pubg-python#ratelimits - after version 0.11.0 (https://github.com/ramonsaraiva/pubg-python/releases/tag/0.11.0 & https://pypi.org/project/pubg-python/0.11.0/)

As per documentation, a snippet like:

api = PUBG('my-super-secret-key', Shard.STEAM)

while True:
    try:
        print('Processing samples...')
        api.samples().get()
    except RateLimitError as error:
        sleep_seconds = (error.rl_reset - datetime.now()).total_seconds()
        if sleep_seconds > 0:
            print('Reached my limit! sleeping for {}'.format(sleep_seconds))
            time.sleep(sleep_seconds)

Would generate this output:

(pubg-python) ~/src/pubg-python (master โœ˜)โœนโœญ แ… python test_ratelimit.py
Processing samples...
Reached my limit! sleeping for 39.307168 seconds
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Processing samples...
Reached my limit! sleeping for 43.842393 seconds

@glmn Iโ€™ll add to the RateLimitException (https://github.com/ramonsaraiva/pubg-python/blob/master/pubg_python/exceptions.py#L45) context the timestamp it will unlock requests.

1 Year Later. ๐Ÿ˜ƒ