0

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!!

zhaoyin
  • 101
  • 1
  • 1
  • possible duplicate of [error: \[Errno 10053\]](http://stackoverflow.com/questions/17854713/error-errno-10053) – Roland Smith Aug 07 '14 at 23:33
  • @Smith I am confused since I turned off the firewall and the network is very good, I mean the speed (nearly 2M per second). Can you kindly tell me how to test and fix it? Thank you! – zhaoyin Aug 08 '14 at 00:06
  • As you can see in the answer I linked to, this is the operating system closing the socket. There are many possible reasons. BTW, if you want to read web pages, do yourself a favor and use [requests](http://docs.python-requests.org/en/latest/). – Roland Smith Aug 08 '14 at 00:44
  • @RolandSmith Thanks! I knew other ways to do it but I wonder why the author of that textbook asks the readers to do it? Anyway, I will try to use other libraries as you mentioned above. Thank you again!! – zhaoyin Aug 08 '14 at 04:49

0 Answers0