0

I'm trying to run the following program, following a tutorial. How should I fix the error shown below?

import re
import urllib

#name=raw_input('Enter URL for the site name:')
handle=urllib.urlopen('http://www.iitk.ac.in')
for line in handle:
    print line.strip()

Error and stack trace:

Traceback (most recent call last):
File "second.py", line 5, in <module>
handle=urllib.urlopen('http://www.iitk.ac.in')
File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 1048, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 892, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 854, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 831, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known
Prune
  • 76,765
  • 14
  • 60
  • 81
  • 1
    possible duplicate of http://stackoverflow.com/questions/4673166/python-httplib-name-or-service-not-known – ᴀʀᴍᴀɴ Jan 06 '16 at 18:38
  • Weird, I tried it and it worked. What version of `urllib` are you using? You can see it with `print urllib.__version__` – William Jan 06 '16 at 18:50

0 Answers0