Loanb222 Loanb222 - 2 months ago 27x
Python Question

How can I use urllib.request.urlretrieve with python 2.7

I am trying to get images dowloaded from so that I can create a haar cascade classifier. I am following this tutorial but I am using python 2.7 instead of python 3. So in the tutorial he has the line:

urllib.request.urlretrieve(img, pathToImage)

Instead of
import urllib.request
I did this
import urllib2
So I tried this but it isn't vaild

urllib2.urlretrieve(i, "Negatives/"+str(num)+".jpg")

Thank you in Advance!


You just need to import urllib without '2'

import urllib
urllib.urlretrieve(i, "Negatives/"+str(num)+".jpg")