AttributeError: ‘module’ object has no attribute ‘urlretrieve’ error occurs when you try to use the urlretrieve method from Python’s urllib library but haven’t imported it correctly.
There are two main reasons for the error.
- Not importing urlretrieve from the correct module in Python 3.
- Using Python 2 (where the structure of urllib was different).
How to fix it?
For Python 3
You need to ensure you are importing urlretrieve from urllib.request.
from urllib.request import urlretrieve
After this import, you can use the urlretrieve function directly:
from urllib.request import urlretrieve data = urlretrieve("https://appdividend.com") print(data)
('/var/folders/8v/x42znv0n7r5383bnmngj4kmw0000gn/T/tmpt51zir6j', <http.client.HTTPMessage object at 0x1012b4070>)
For Python 2
In Python 2, urlretrieve is part of the urllib module (not urllib.request). So, the import statement will be:
from urllib import urlretrieve
However, I recommend you migrate to Python 3 if possible, as Python 2 has reached its end of life and is no longer maintained.