avoid infinite loops in case of 403 errors
This commit is contained in:
parent
ae09a1d981
commit
60601ea061
1 changed files with 5 additions and 1 deletions
|
@ -14,6 +14,7 @@ from datetime import datetime, timedelta
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from random import random
|
from random import random
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
import acoustid
|
import acoustid
|
||||||
import filetype
|
import filetype
|
||||||
|
@ -190,13 +191,16 @@ class DelojzaBot:
|
||||||
}]
|
}]
|
||||||
filenames = []
|
filenames = []
|
||||||
with youtube_dl.YoutubeDL(ytdl) as ytdl:
|
with youtube_dl.YoutubeDL(ytdl) as ytdl:
|
||||||
|
attempts = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
ytdl.download(urls)
|
ytdl.download(urls)
|
||||||
break
|
break
|
||||||
except DownloadError as exc:
|
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!")
|
self.logger.warning("Received a 403!")
|
||||||
|
sleep(1.357)
|
||||||
if self.markov:
|
if self.markov:
|
||||||
message.reply_text(self.markov.make_sentence)
|
message.reply_text(self.markov.make_sentence)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue