mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-09 09:59:51 +01:00
add a custom message for cloudflare protected mirrors
This commit is contained in:
parent
850c88b398
commit
a32b3742e0
@ -163,7 +163,15 @@ def remote(printer, pages, category, sort, mode, terms, mirror):
|
|||||||
req = request.Request(mirror + path,
|
req = request.Request(mirror + path,
|
||||||
headers=pirate.data.default_headers)
|
headers=pirate.data.default_headers)
|
||||||
req.add_header('Accept-encoding', 'gzip')
|
req.add_header('Accept-encoding', 'gzip')
|
||||||
f = opener.open(req, timeout=pirate.data.default_timeout)
|
|
||||||
|
try:
|
||||||
|
f = opener.open(req, timeout=pirate.data.default_timeout)
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
res = e.fp.read().decode()
|
||||||
|
if e.code == 503 and 'cf-browser-verification' in res:
|
||||||
|
raise IOError('Cloudflare protected')
|
||||||
|
raise e
|
||||||
|
|
||||||
if f.info().get('Content-Encoding') == 'gzip':
|
if f.info().get('Content-Encoding') == 'gzip':
|
||||||
f = gzip.GzipFile(fileobj=BytesIO(f.read()))
|
f = gzip.GzipFile(fileobj=BytesIO(f.read()))
|
||||||
res = f.read().decode('utf-8')
|
res = f.read().decode('utf-8')
|
||||||
|
Loading…
Reference in New Issue
Block a user