Determine type of URLError

This commit is contained in:
CreateSource 2024-11-23 14:11:44 -05:00 committed by GitHub
parent b26b99e9e3
commit 9a4fb87d44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 1 deletions

View File

@ -123,6 +123,8 @@ def main() -> None:
with urllib.request.urlopen(req) as response: with urllib.request.urlopen(req) as response:
download(url, response, output) download(url, response, output)
except urllib.error.URLError as e: except urllib.error.URLError as e:
if str(e).find("CERTIFICATE_VERIFY_FAILED") == -1:
return
try: try:
import certifi import certifi
import ssl import ssl
@ -133,6 +135,5 @@ def main() -> None:
with urllib.request.urlopen(req, context=ssl.create_default_context(cafile=certifi.where())) as response: with urllib.request.urlopen(req, context=ssl.create_default_context(cafile=certifi.where())) as response:
download(url, response, output) download(url, response, output)
if __name__ == "__main__": if __name__ == "__main__":
main() main()