1
0
Fork 0

Merge pull request #33 from manos/retry-after

honor HTTP retry-after header for better success
This commit is contained in:
Ash Wilson 2019-09-04 14:08:24 -04:00 committed by GitHub
commit cbc44fa0b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 3 deletions

View File

@ -158,15 +158,13 @@ def upload_emoji(session, emoji_name, filename):
'token': session.api_token
}
i = 0
while True:
i += 1
with open(filename, 'rb') as f:
files = {'image': f}
resp = session.post(session.url_add, data=data, files=files, allow_redirects=False)
if resp.status_code == 429:
wait = 2**i
wait = int(resp.headers.get('retry-after', 1))
print("429 Too Many Requests!, sleeping for %d seconds" % wait)
sleep(wait)
continue