From 60601ea061b03e3e820cfb5e7658a1d0113b4d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 31 May 2019 17:53:40 +0200 Subject: [PATCH] avoid infinite loops in case of 403 errors --- delojza.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/delojza.py b/delojza.py index 4f6a9bf..01854b5 100755 --- a/delojza.py +++ b/delojza.py @@ -14,6 +14,7 @@ from datetime import datetime, timedelta from glob import glob from operator import itemgetter from random import random +from time import sleep import acoustid import filetype @@ -190,13 +191,16 @@ class DelojzaBot: }] filenames = [] with youtube_dl.YoutubeDL(ytdl) as ytdl: + attempts = 0 while True: try: ytdl.download(urls) break except DownloadError as exc: - if '403' in str(exc): + attempts += 1 + if '403' in str(exc) and attempts < 5: self.logger.warning("Received a 403!") + sleep(1.357) if self.markov: message.reply_text(self.markov.make_sentence) else: