Skip to content

Commit

Permalink
Fixing HTTP Error 429
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InesPM authored Sep 12, 2023
1 parent 988a5c5 commit b36d653
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frbcat/tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b36d653

Please sign in to comment.