AttributeError: 'module' object has no attribute 'request'

Pruthvi Raj picture Pruthvi Raj · Mar 9, 2014 · Viewed 92.5k times · Source

When I run the following code in Python 3.3:

import urllib
tempfile = urllib.request.urlopen("http://yahoo.com")

I get the following error:

enter image description here

I did this too to verify:

enter image description here

What am I doing wrong?

Answer

falsetru picture falsetru · Mar 9, 2014

The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.


Import urllib.request instead of urllib.

import urllib.request