[Python] ConnectionResetError: [Errno 104] Connection reset by peer

python socket 编程,sftp远程读日志文件,取最后的30行返回。收到ConnectionResetError: [Errno 104] Connection reset by peer报错。
最后找到原因是send的数据size太大,服务器端重置了连接


Traceback (most recent call last):
  File "s1.py", line 63, in <module>
    data = tcpCliSock.recv(bufsize).decode()
ConnectionResetError: [Errno 104] Connection reset by peer


解决办法:把异常by pass

from socket import error as SocketError
import errno

try:
     ...

     ...
except SocketError as e:
    if e.errno != errno.ECONNRESET:
        raise
    pass




©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页