binoua commited on
Commit
3d2d528
1 Parent(s): 1bb01e9

chore: adding a retry.

Browse files
Files changed (1) hide show
  1. play_with_endpoint.py +9 -3
play_with_endpoint.py CHANGED
@@ -27,11 +27,17 @@ headers = {
27
  }
28
 
29
 
30
- def query(payload):
31
  response = requests.post(API_URL, headers=headers, json=payload)
32
 
33
- if "error" in response:
34
- assert False, f"Got an error: {response=}"
 
 
 
 
 
 
35
 
36
  return response.json()
37
 
 
27
  }
28
 
29
 
30
+ def query(payload, allowed_retries=2):
31
  response = requests.post(API_URL, headers=headers, json=payload)
32
 
33
+ if "error" in response.json():
34
+ if allowed_retries > 0:
35
+ # Sometimes we have "Bad gateway" error
36
+ print(f"Warning, error {response=} {response.json()=} in the query, relaunching")
37
+
38
+ return query(payload, allowed_retries - 1)
39
+
40
+ assert False, f"Got an error: {response=} {response.json()=}"
41
 
42
  return response.json()
43