SSLError, URLError – URL fetch error occurs Keras, Python

By | April 7, 2018

SSLError, URLError – URL fetch error occurs Keras, Python

Recently, I was trying to use pre-trained InceptionResNetV2 model in one of my project. The following error(sslerror) occurred when the program tried to download the weights of the pre-trained model:

“SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)”

“URLError: <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)>”

“Exception: URL fetch failure on None — [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)”

System description

macOS Sierra – version 10.12.5

Python 3.6

Keras 2.1.4


After struggling for some time, I resolved the issue. The error was due the older version of OpenSSL. I will describe here all the steps that I went through.

  • As described in a Stack Overflow solution, I read the readme.rtf file in Applications -> Python 3.6 directory. It suggests you to run Install Certificates.command located in the same directory.
  • The above step should have solved my problem. But I was using Python virtual environment. So, in virtualenv OpenSSL did not update. See the image below:
sslerror, urlerror

sslerror, urlerror

  • It can be seen in the image that the openssl versions differ in default environment and in virtual environment.

Use the following command to check openssl version:

  • Trying pip install for openssl did not seem to be working in my case. So, I used Homebrew installation(warning: this action uninstalled all other packages from the virtualenv like keras, tensorflow, numpy etc. and I had to reinstall them) as following:

  • As I was running through many errors caused by brew update in the current virtualenv. I decided to create different virtualenv. To create new Python virtualenv use the following command:

In this new virtualenv, I installed all libraries required for deep learning. Also, it is good to check the openssl version in this virtualenv. Use the command described above. This blog may help you learn which libraries one must have installed and how to make your machine ready for deep learning.