From 3ad8620fbd17fde848916cb529bfadad34647b9c Mon Sep 17 00:00:00 2001 From: morhook Date: Sat, 20 Jun 2020 17:16:16 -0300 Subject: [PATCH] Fixed error handling On my computer it's failing on the first request to https://thepiratebay.org/ . I think the properties this code is handling need an HTTPError according to the doc https://docs.python.org/3/library/urllib.error.html\#urllib.error.URLError --- pirate/torrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pirate/torrent.py b/pirate/torrent.py index ec39f77..4ad9086 100644 --- a/pirate/torrent.py +++ b/pirate/torrent.py @@ -146,7 +146,7 @@ def find_api(mirror, timeout): f = request.urlopen(req, timeout=timeout) if f.info().get_content_type() == 'application/json': return mirror + path - except urllib.error.URLError as e: + except urllib.error.HTTPError as e: res = e.fp.read().decode() if e.code == 503 and 'cf-browser-verification' in res: raise IOError('Cloudflare protected')