使用Python套接字时出现错误10053

时间:2014-08-07 22:35:43

标签: python sockets

我遵循了Python texbook“Python for Informatics”的指令。问题是请求文档并显示服务器发回的内容。代码如下:

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()

然而它返回一条错误消息:

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

我找到了一些描述这个问题的帖子,但我真的需要一个解决方案来解决它。我的操作系统是Win7 64位,Python 2.7。

谢谢!

0 个答案:

没有答案