Import Doesn't Import

Chris Rebert clp2 at rebertia.com
Wed Oct 15 21:21:25 EDT 2014


On Wednesday, October 15, 2014, ryguy7272 <ryanshuell at gmail.com> wrote:

> So sorry everyone.  I've posted here several times today.  This is VERY
> frustrating.
>
> So, I'm reading this link.
> https://docs.python.org/2/howto/urllib2.html
>

>
Important note!: The "/2/" in the URL means those docs are for Python 2.x
When using Python 3, ensure that the docs you're consulting have a "/3/" in
them instead.


> Fetching URLs
> The simplest way to use urllib2 is as follows:
> import urllib2
> response = urllib2.urlopen('http://python.org/')
> html = response.read()
>
>
> So, I fire up Python, and create a new file and name it and hit F5.
>
> All I have is thins in the file:
> import urllib2
> response = urllib2.urlopen('http://python.org/')
> html = response.read()
>
> It immediately produces this error:
> Traceback (most recent call last):
>   File "C:/Python34/import_web_data.py", line 1, in <module>
>     import urllib2
> ImportError: No module named 'urllib2'
>
>
You're using Python 3, and the urllib2 module no longer exists in Python 3.
The URL/HTTP modules got refactored on Python 3. You want the
`urllib.request` module instead.

Although most folks nowadays use http://docs.python-requests.org/ instead,
though it's third-party and outside the std lib.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141015/601603ce/attachment.html>


More information about the Python-list mailing list