IO error in Python

I am trying to run this code:

    import urllib
    htmlfile = urllib.urlopen("https://www.google.co.in/?gfe_rd=cr&ei=7VzrV6WWG8KC0ATxor_IDw")
    htmltext = htmlfile.read()
    print htmltext

But the following error is shown, when I run the code:

    Traceback (most recent call last):
    File "C:\Python27\newscrap.py", line 2, in <module>
    htmlfile = urllib.urlopen("https://www.google.co.in/?gfe_rd=cr&ei=7VzrV6WWG8KC0ATxor_IDw")
    File "C:\Python27\lib\urllib.py", line 87, in urlopen
    return opener.open(url)
    File "C:\Python27\lib\urllib.py", line 213, in open
    return getattr(self, name)(url)
    File "C:\Python27\lib\urllib.py", line 443, in open_https
h.endheaders(data)
    File "C:\Python27\lib\httplib.py", line 997, in endheaders
self._send_output(message_body)
    File "C:\Python27\lib\httplib.py", line 850, in _send_output
self.send(msg)
    File "C:\Python27\lib\httplib.py", line 812, in send
self.connect()
    File "C:\Python27\lib\httplib.py", line 1208, in connect
HTTPConnection.connect(self)
    File "C:\Python27\lib\httplib.py", line 793, in connect
self.timeout, self.source_address)
    File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
     IOError: [Errno socket error] [Errno 11004] getaddrinfo failed

Can anyone tell why this error occurs?

Upvotes: 0

Views: 82

Answers (1)

sokoli
sokoli

Reputation: 515

It's a connection problem (your code works on my computer). Check your firewall / proxy settings / dns server / other connection settings.

Upvotes: 1

Related Questions