No request in module urllib ?

Chris Angelico rosuav at gmail.com
Thu Sep 3 22:08:07 EDT 2015


On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
<vincent.vande.vyvre at telenet.be> wrote:
> Python 3.2.3 (default, Jun 18 2015, 21:46:42)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import urllib
>>>> urllib.request.urlopen('http://example.org')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'request'
>
> Same error with Python 3.4.0

With packages, like this, you sometimes need to explicitly import the
piece you want. That way, the urllib module doesn't have to load
everything up just because you wanted one small part. Try this
instead:

import urllib.request
urllib.request.urlopen('http://example.org')

Hope that helps!

ChrisA



More information about the Python-list mailing list