I must say this error looks suspicious but what I believe this error occurs because host (virtual) machine is not able to reach the docker repository or having connection issues. I was getting this error while I was trying to pull an image.
In my case, I was using HTTP proxy on my virtual box to connect to the internet.
I noticed my proxy password was having some special characters and it was malfunctioning the code compilation.
How did I get to know? I tried installing some package from Python PIP package Installer which exposed the code error more clear.
The solution for me: I updated my proxy password without special characters that are used in either in the regular expression or in host connection. Now everything works fine for me.