Skip to content

Commit

Permalink
Merge branch 'bugfix/rate_limit_reached' into 'develop'
Browse files Browse the repository at this point in the history
Fixed rate limit reached and empty file download bug

See merge request core/sevenbridges-python!61
  • Loading branch information
Aleksandar Pavlovic committed Apr 15, 2020
2 parents 14cf41d + d32bed7 commit 159101a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions sevenbridges/http/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def rate_limit_sleeper(api, response):
while response.status_code == 429:
headers = response.headers
remaining_time = headers.get('X-RateLimit-Reset')
sleep = int(remaining_time) - int(time.time())
sleep = max(int(remaining_time) - int(time.time()), 0)

logger.warning('Rate limit reached! Waiting for [%s]s', sleep)
time.sleep(sleep + 5)
time.sleep(sleep)

response = api.session.send(response.request)
return response

Expand Down
2 changes: 1 addition & 1 deletion sevenbridges/transfer/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,6 @@ def _get_file_size(self):
)
file_size = int(file_size)
if file_size == 0:
with io.open(self._file_path, 'a', encoding='utf-8'):
with io.open(self._temp_file, 'a', encoding='utf-8'):
pass
return file_size

0 comments on commit 159101a

Please sign in to comment.