Sometimes, we want to fix Import error: No module name urllib2 with Python.
In this article, we’ll look at how to fix Import error: No module name urllib2 with Python.
How to fix Import error: No module name urllib2 with Python?
To fix Import error: No module name urllib2 with Python, we can use the right module of urllib
.
For instance, we write
from urllib.request import urlopen
html = urlopen("http://www.google.com/").read()
print(html)
to import urlopen
from the urllib.request
module.
Then we call urlopen
to open http://www.google.com/ and get the response with read
.
Conclusion
To fix Import error: No module name urllib2 with Python, we can use the right module of urllib
.