Import error: No module name urllib2

0 votes

Here's my code:

import urllib2.request

response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)

Any help?

May 11 in Python by kartik
• 11,890 points
41 views

1 answer to this question.

0 votes

As stated in the urllib2 documentation:

The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

So you should instead be saying

from urllib.request import urlopen
html = urlopen("http://www.google.com/").read()
print(html)

Your current, now-edited code sample is incorrect because you are saying urllib.urlopen("http://www.google.com/") instead of just urlopen("http://www.google.com/").

Thank You!!

answered May 11 by Niroj
• 23,950 points

Related Questions In Python

0 votes
1 answer

Python error " import requests ImportError: No module named requests"

Hi @Vasgi, for the code you're trying ...READ MORE

answered Aug 5, 2019 in Python by Layla
4,407 views
0 votes
1 answer

No module name scikitplot

To overcome this issue, you need to ...READ MORE

answered Mar 9, 2019 in Python by Siri
2,510 views
0 votes
1 answer

Python error "ImportError: No module named pygame.locals"

You need to download and install the ...READ MORE

answered Jun 18, 2019 in Python by Greg
1,356 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 963 views
0 votes
0 answers
0 votes
1 answer

Error: import No module name urllib2

Hii, You have to install the modules like bs4, ...READ MORE

answered May 5 in Python by Niroj
• 23,950 points
51 views
0 votes
1 answer

Import Error: No module named numpy?

Hello, I had numpy installed on the same ...READ MORE

answered Apr 14 in Python by Niroj
• 23,950 points
432 views