October 19, 2024

About

If you don’t have SSL certificate, downloading files sometimes get failed. And the error like ssl.SSLError happens. Here shows a bad tips to avoid it. Since what you need is to have certificate.

import ssl
import urllib.request
with urllib.request.urlopen(url) as f:
    response = f.read()
import ssl
import urllib.request
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(url, context=context) as f:
    response = f.read()