avoid infinite loops in case of 403 errors

This commit is contained in:
Tomáš Mládek 2019-05-31 17:53:40 +02:00
parent ae09a1d981
commit 60601ea061

View file

@ -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: