From efa7cc7e6dd1b049c4297d69f0dd7203ef392529 Mon Sep 17 00:00:00 2001 From: Shayki Abramczyk Date: Wed, 17 Apr 2024 09:35:34 +0300 Subject: [PATCH] add try-catch --- bot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 18caf6d1..17b79b39 100644 --- a/bot.py +++ b/bot.py @@ -36,10 +36,16 @@ def get_data_from_sheets_on_start(): # Get all values from column D column_d_values = sheet.col_values(4) # Get values from column D (index 4) print(column_d_values) - time.sleep(120) + time.sleep(80) for index, value in enumerate(column_d_values, start=1): - corresponding_value_e = sheet.cell(index, 5).value - print(corresponding_value_e) + try: + corresponding_value_e = sheet.cell(index, 5).value + print(corresponding_value_e) + except gspread.exceptions.APIError as e: + print(f"Encountered APIError: {e}") + print("Retrying after a delay...") + time.sleep(30) # Wait for 30 seconds before retrying + corresponding_value_e = sheet.cell(index, 5).value if corresponding_value_e == "not found": states['not_found_values'].append(value) if states['not_found_values']: