Skip to content

fix: Automatically delay and refetch if 429#177

Merged
hanjano merged 3 commits intomasterfrom
fix-rate-limit-issue
Feb 29, 2024
Merged

fix: Automatically delay and refetch if 429#177
hanjano merged 3 commits intomasterfrom
fix-rate-limit-issue

Conversation

@hanjano
Copy link
Copy Markdown
Contributor

@hanjano hanjano commented Feb 29, 2024

No description provided.

Comment thread blockapi/v2/base.py
Comment on lines +93 to +121
while True:
response = self._get_response(request_method, headers, params, req_args)
time = self._get_response_time(response.headers)
if response.status_code == 200:
return FetchResult(
status_code=response.status_code,
headers=self._get_headers_dict(response.headers),
data=response.json(**self.json_parse_args),
extra=extra,
time=time,
)

if response.status_code == 429 and self.sleep_provider:
delay = response.headers.get('retry-after', '60')
try:
seconds = int(delay)
except ValueError:
seconds = 60

logger.warning(
f'Too Many Requests: Will retry after {seconds}s sleep'
)
self.sleep_provider.sleep(self.base_url, seconds=seconds)
continue

break
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially this could be infinite cycle, in case there is another parallel blockapi instance, or third-party blocked us permanently

please add some retry_count argument, default value 3 or 5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, i think

@hanjano hanjano force-pushed the fix-rate-limit-issue branch from 1820081 to dbf6296 Compare February 29, 2024 14:20
@hanjano hanjano merged commit 11ad0aa into master Feb 29, 2024
@hanjano hanjano deleted the fix-rate-limit-issue branch February 29, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants