mardi 26 juillet 2016

Error 11001 while running a python code with Socket

I have been trying to run the python code attached below but I keep getting a error. Can someone tell me what's the issue or how can I solve it? Thanks!

Code:

import socket

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.py4inf.com', 80))
mysock.send('GET http://ift.tt/1sCbd7y HTTP/1.0\n\n')

while True:
    data = mysock.recv(512)
    if ( len(data) < 1 ) :
        break
print data;

mysock.close()

Error I get when I run the code

Error:

Traceback (most recent call last):
  File "C:\Users\******\Desktop\Python\Programs\socket2.py", line 4, in    <module>
mysock.connect(('www.py4inf.com', 80))
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno 11001] getaddrinfo failed




Aucun commentaire:

Enregistrer un commentaire