Skip to content

Commit 8dc3885

Browse files
committed
Handle ChunkedEncodingError in retries
1 parent 3a1664f commit 8dc3885

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

devstats/query.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,22 @@ def send_query(query, query_type, headers, cursor=None):
8787
# Build request payload
8888
payload = {"query": "".join(query.split("\n"))}
8989

90-
retry = True
91-
while retry:
92-
response = requests.post(endpoint, json=payload, headers=headers)
93-
data = json.loads(response.content)
94-
if "exceeded a secondary rate limit" in data.get("message", ""):
95-
print("Secondary rate limit exceeded; sleeping 2mins")
96-
time.sleep(2 * 60)
90+
retries = 10
91+
while retries > 0:
92+
try:
93+
response = requests.post(endpoint, json=payload, headers=headers)
94+
except requests.exceptions.ChunkedEncodingError as e:
95+
print(f"`requests` ChunkedEncodingError: {e}; retrying.")
96+
retries -= 1
9797
else:
98-
retry = False
98+
data = json.loads(response.content)
99+
if "exceeded a secondary rate limit" in data.get("message", ""):
100+
print("GitHub secondary rate limit exceeded; retrying after 2mins")
101+
time.sleep(2 * 60)
102+
retries -= 1
103+
else:
104+
# Success
105+
retries = 0
99106

100107
rate_limit = {h: response.headers[h] for h in ("x-ratelimit-remaining",)}
101108
return {**data, **rate_limit}

0 commit comments

Comments
 (0)