Skip to content

Instantly share code, notes, and snippets.

@mwfarb
Last active November 14, 2021 22:07
Show Gist options
  • Save mwfarb/c45958c321f021b3b472248c1e4cfc5d to your computer and use it in GitHub Desktop.
Save mwfarb/c45958c321f021b3b472248c1e4cfc5d to your computer and use it in GitHub Desktop.
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