Categories
Python Answers

How to fix Import error: No module name urllib2 with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *