Search code examples
pythonurllib2

How to disable SSL verification for urlretrieve?


A similar question had been asked a couple times around SO, but the solutions are for urlopen. That function takes an optional context parameter which can accept a pre-configured SSL context. urlretrieve does not have this parameter. How can I bypass SSL verification errors in the following call?

urllib.request.urlretrieve(
    "http://sourceforge.net/projects/libjpeg-turbo/files/1.3.1/libjpeg-turbo-1.3.1.tar.gz/download", 
    destFolder+"/libjpeg-turbo.tar.gz")

Solution

  • 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/