How to disable SSL verification for urlretrieve?

This solution worked as well for me: before making the call to the library, define the default SSL context:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# urllib.request.urlretrieve(...)

Source: http://thomas-cokelaer.info/blog/2016/01/python-certificate-verified-failed/


This does not appear to be possible with urlretrieve (in Python >=2.7.9, or Python >=3.0).

The requests package is recommended as a replacement.

Edited to add: the context parameter has been added to the code, even though it isn't mentioned in the documentation! Hat-tip @Sushisource

Tags:

Python

Urllib2