Ignore cert errors during book download
Some checks failed
Build binaries / build (push) Has been cancelled
Build binaries / test-python3 (3.10) (push) Has been cancelled
Build binaries / test-python3 (3.11) (push) Has been cancelled
Build binaries / test-python3 (3.12) (push) Has been cancelled
Build binaries / test-python3 (3.6) (push) Has been cancelled
Build binaries / test-python3 (3.7) (push) Has been cancelled
Build binaries / test-python3 (3.8) (push) Has been cancelled
Build binaries / test-python3 (3.9) (push) Has been cancelled
Build binaries / test-python2 (push) Has been cancelled
Build binaries / test-ubuntu-2004 (push) Has been cancelled
Build binaries / test-ubuntu-2204-oscrypto (push) Has been cancelled
Build binaries / test-ubuntu-2204-oscrypto-fork (push) Has been cancelled
Build binaries / test-windows (push) Has been cancelled
Build binaries / test-mac (push) Has been cancelled

Fixes #97
This commit is contained in:
Florian Bach 2024-09-17 19:21:56 +02:00
parent 2dcf26be18
commit 2f40289a84

View file

@ -252,8 +252,26 @@ def sendHTTPRequest_DL2FILE(URL, outputfile):
"User-Agent": "book2png",
# MacOS uses different User-Agent. Good thing we're emulating a Windows client.
}
# Ignore SSL:
# It appears as if lots of book distributors have either invalid or expired certs ...
# No idea how Adobe handles that (pinning?), but we can just ignore SSL errors and continue anyways.
# Not the best solution, but it works.
try:
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# This is needed due to an Adobe change.
# Without this, only Python <= 3.7.16 can connect, 3.7.17 and above fail.
# Cloudflare detects that Python uses TLS1.3 which ADE doesn't support, so
# just enforce TLSv1.2 here.
except:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
req = ulib.Request(url=URL, headers=headers)
handler = ulib.urlopen(req)
handler = ulib.urlopen(req, context=ctx)
chunksize = 16 * 1024
@ -298,6 +316,8 @@ def sendHTTPRequest_getSimple(URL):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# This is needed due to an Adobe change.
# Without this, only Python <= 3.7.16 can connect, 3.7.17 and above fail.
# Cloudflare detects that Python uses TLS1.3 which ADE doesn't support, so
# just enforce TLSv1.2 here.
except:
ctx = ssl.create_default_context()
@ -338,6 +358,8 @@ def sendPOSTHTTPRequest(URL, document, type, returnRC = False):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# This is needed due to an Adobe change.
# Without this, only Python <= 3.7.16 can connect, 3.7.17 and above fail.
# Cloudflare detects that Python uses TLS1.3 which ADE doesn't support, so
# just enforce TLSv1.2 here.
except:
ctx = ssl.create_default_context()