I followed the instruction of a Python texbook 'Python for Informatics'. The question is to request a document and display what the sever sends back. The code is following:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.py4inf.com', 80))
mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n')
while True:
data = mysock.recv(512)
if (len(data) < 1) :
break
print data;
mysock.close()
Yet it returns an error message:
---------------------------------------------------------------------------
error Traceback (most recent call last)
C:\Users\Fujitsu\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
195 else:
196 filename = fname
--> 197 exec compile(scripttext, filename, 'exec') in glob, loc
198 else:
199 def execfile(fname, *where):
D:\E-learning_courses\Python\Programming for Everybody\TextBook\code\socket1.py in <module>()
6
7 while True:
----> 8 data = mysock.recv(512)
9 if (len(data) < 1) :
10 break
error: [Errno 10053] An established connection was aborted by the software in your host machine
I have found some posts describing this problem but I really need a solution to fix it. My OS is Win7 64-bit, Python 2.7.
Thank you!!