-
-
Save mwfarb/c45958c321f021b3b472248c1e4cfc5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import ssl | |
import urllib.request | |
openssl_dir, openssl_cafile = os.path.split( | |
ssl.get_default_verify_paths().openssl_cafile) | |
# no content in this folder | |
os.listdir(openssl_dir) | |
# non existent file | |
ssl_file = os.path.join(openssl_dir, openssl_cafile) | |
cert_exists = os.path.exists(ssl_file) | |
print(f"File {ssl_file} exists? {cert_exists}.") | |
urls = [ | |
'https://sha256.badssl.com/', # should succeed | |
'https://arenaxr.org/conf/gauth.json', # should succeed | |
'https://untrusted-root.badssl.com/', # should fail | |
] | |
for url in urls: | |
print(f"Testing {url}...") | |
try: | |
with urllib.request.urlopen(url) as response: | |
html = response.read() | |
except os.error as err: | |
print(f"URL failed. {err=}, {type(err)=}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment