From 19e812fb9ded633ac1d972df8dafc00199610763 Mon Sep 17 00:00:00 2001 From: Oleg Gratilo <54913268+gratilo@users.noreply.github.com> Date: Fri, 13 Oct 2023 17:36:20 +0300 Subject: [PATCH] Update get_sales_data fixed IndexError if list index out of range --- wbparser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wbparser.py b/wbparser.py index f585e36..94ae6f2 100644 --- a/wbparser.py +++ b/wbparser.py @@ -311,7 +311,10 @@ def get_sales_data(self): f"?nm={card['Артикул']}") try: response = requests.get(url, headers=self.headers).json() - card['Продано'] = response[0]['qnt'] + if response == []: + card['Продано'] = 'неизвестно' + else: + card['Продано'] = response[0]['qnt'] except requests.ConnectTimeout: card['Продано'] = 'нет данных' print(f"Собрано карточек: {self.product_cards.index(card) + 1}"