Not recognizing urllib2


#1

I’m going through the final project worksheet and they have us check the following code. urllib2 is suppose to be in python and that’s why I’m confused by how it’s not being recognized as I try to import it. Could it be a syntax issue?



import urllib2

response=urllib2.urlopen('http://gutenberg.org/')
html=response.read()

print (html)






#2

Hi @mikeman92,

Codecademy based this project on Python 2. Are you using Python 3, instead? If so, then you will need to use urllib, since in Python 3 it replaces urllib2. Some of the functionality of urllib is different from that of urllib2. This would require you to modify code within the files that Codecademy supplies for the project, and to make some departures from the instructions.

Using Python 3 can work with this project, provided that you are willing to put in the effort to learn the differences between the two versions and to make the necessary adjustments. Otherwise, it will be necessary to work with Python 2, as Codecademy intended.


#3

Thank you for the clarification appylpye. I’ve originally had python 3 installed before python 2 and I’ve been having trouble getting my interpreter to recognize it. This is something I’m still looking into.