Skip to content

Commit

Permalink
honor HTTP retry-after header for better success
Browse files Browse the repository at this point in the history
  • Loading branch information
manos committed Sep 4, 2019
1 parent 4cb3675 commit edf0dd3
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit edf0dd3

Please sign in to comment.