I am on Ubuntu 16.10. I am trying to download an image using urlretrieve()
function of python. I am getting the following errors.
File "downloadImage.py", line 9, in <module>
downloadWebImage("https://qph.ec.quoracdn.net/main-qimg-601accaf841bba9145d3c46bece1ea10-p")
File "downloadImage.py", line 7, in downloadWebImage
urllib.urlretrieve(url, fullName)
File "/usr/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "/usr/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)
File "/usr/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 443, in open_https
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 897, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 859, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 1278, in connect
server_hostname=server_hostname)
File "/usr/lib/python2.7/ssl.py", line 353, in wrap_socket
_context=self)
File "/usr/lib/python2.7/ssl.py", line 601, in __init__
self.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 830, in do_handshake
self._sslobj.do_handshake()
IOError: [Errno socket error] [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
Also my code is :
import random
import urllib
def downloadWebImage(url):
name = random.randrange(1,1000)
fullName = str(name) + '.jpg'
urllib.urlretrieve(url, fullName)
downloadWebImage("https://qph.ec.quoracdn.net/main-qimg-601accaf841bba9145d3c46bece1ea10-p")
So what are the errors, why are they occuring? What is their fix?