From b36d653a926f4eec0ba4e58d8f8a2f0db089f418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?In=C3=A9s=20Pastor-Marazuela?= <29770213+InesPM@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:25:25 +0100 Subject: [PATCH] Fixing HTTP Error 429 Fixing HTTP Error 429: Too Many Requests. This showed up with get_json(), and seems to be fixed when adding a page_length limit of 50 and a sleep time of 0.5 to 1 seconds. --- frbcat/tns.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frbcat/tns.py b/frbcat/tns.py index 3efe856..76628fe 100644 --- a/frbcat/tns.py +++ b/frbcat/tns.py @@ -167,11 +167,18 @@ def row2json(self, line): print(key, val) return out - def get_json(self): + def get_json(self, page_length=50, sleep=0.5): + """ + Get TNS catalogue in json file format. + page_length and sleep avoid HTTP Error 429: Too Many Requests. + Args: + page_length (int): Limit of items per page that can be queried. + sleep (float): sleep time between queried pages. + """ entries = [] more = True page = 0 - page_length = 500 + page_length = 50 if page_length > 50 else page_length if not self.mute: m = 'Attempting to retrieve FRBs from the Transient Name Server'