How to Solve NameError: name 'urllib2' is not defined

Solution: Import the 'urllib2' module

# Add the following line to the top of your code
import urllib2

 

For more information:
Python urllib2