Malfrats / xeuledoc

Fetch information about a public Google document.
https://malfrats.industries/
GNU General Public License v3.0
833 stars 90 forks source link

Rate Limit Exceeded Error #3

Closed GuillaumeFalourd closed 3 years ago

GuillaumeFalourd commented 3 years ago

Sometimes, the request can return the following message:

{'error': {'errors': [{'domain': 'usageLimits', 'reason': 'rateLimitExceeded', 'message': 'Rate Limit Exceeded'}], 'code': 403, 'message': 'Rate Limit Exceeded'}}

In that case, the code breaks and returns:

created_date = datetime.strptime(data["createdDate"], '%Y-%m-%dT%H:%M:%S.%fz')
KeyError: 'createdDate'

This is just a check to return a friendly message to the user instead of the error above.

mxrch commented 3 years ago

Thank you for this PR, I'll just add retries before exiting in your PR

GuillaumeFalourd commented 3 years ago

If you want I can update the code to something like this:

if "rateLimitExceeded" in req.text:
        for i in range(0,5):
            req = client.get(url)
            if "rateLimitExceeded" in req.text and i == 4:
                print("Rate Limit Exceeded. Try again later.")
                exit()
            else:
                continue