INNER CODE UNIT · Python
execute_query
simonw/simonw · build_readme.py:22
def execute_query(query):
"""Run a GraphQL query, retrying transient gateway errors with backoff."""
for attempt in range(MAX_RETRIES):
try:
return client.execute(
query=query,
headers={"Authorization": "Bearer {}".format(TOKEN)},
)
except requests.exceptions.HTTPError as error:
response = error.response
status = response.status_code if response is not None else None
if status not in RETRYABLE_STATUS or attempt == MAX_RETRIES - 1:
raise
print(" GraphQL {} error, retrying...".format(status))
except requests.exceptions.RequestException:
if attempt == MAX_RETRIES - 1:
raise
print(" GraphQL network error, retrying...")