Python 错误:[错误 10053]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17854713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:19:26  来源:igfitidea点击:

error: [Errno 10053]

pythonflask

提问by Patrick Burns

If I am coding on Flask, then I sometimes get this error:

如果我在 Flask 上编码,那么我有时会收到此错误:

Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 640, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] ????????? ?? ????? ????-

Any ideas why this would happen (win8 x64, python27 x32)?

任何想法为什么会发生这种情况(win8 x64,python27 x32)?

回答by Martijn Pieters

From the Windows Sockets Error Codeslist:

Windows 套接字错误代码列表:

WSAECONNABORTED10053
Software caused connection abort.
An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error.

WSAECONNABORTED10053
软件导致连接中止。
已建立的连接被主机中的软件中止,可能是由于数据传输超时或协议错误。

There was a timeout or other network-level error. This is your operating system closing the socket, nothing to do with Python or Flask, really.

出现超时或其他网络级错误。这是您的操作系统关闭了套接字,与 Python 或 Flask 无关,真的。

It could be the remote browser stopped responding, the network connection died, or a firewall closed the connection because it was open too long, or any other number of reasons.

可能是远程浏览器停止响应,网络连接中断,或者防火墙因为连接打开时间过长而关闭了连接,或者任何其他原因。

回答by Nop

I recently ran into this error message while trying to use Flask to serve audio files. I get this error message whenever the client closes the stream before the end of the stream. Flask continues to try to write data to the stream, but since the underlying socket has been disconnected, it can't. This isn't actually an errorper se, but rather a message informing you that the connection to the client has been closed before Flask finished writing data to the stream.

我最近在尝试使用 Flask 提供音频文件时遇到了此错误消息。每当客户端在流结束之前关闭流时,我都会收到此错误消息。Flask 继续尝试向流中写入数据,但由于底层套接字已断开连接,因此不能。这实际上并不是错误本身,而是一条消息,通知您在 Flask 完成将数据写入流之前与客户端的连接已关闭。

回答by Dabay Wang

I met this problem when reading response from a web server. For my case, the problem was I close the socket connection too early that it broke the communications. So I sleep some seconds before receiving data and then close the socket connection.

我在从 Web 服务器读取响应时遇到了这个问题。就我而言,问题是我过早关闭套接字连接而导致通信中断。所以我在接收数据之前睡了几秒钟,然后关闭套接字连接。

time.sleep(10)
data = s.recv(1024)
s.close()

It works for me.

这个对我有用。

回答by jayant singh

It's a PIPE error, which occurs if the server responds to a request and the client has already closed the connection. Browsers do that sometimes depending on usage. You can ignore those, web servers suited for production certainly will.

这是一个 PIPE 错误,如果服务器响应请求并且客户端已经关闭连接,就会发生这种错误。浏览器有时会根据使用情况执行此操作。您可以忽略这些,适合生产的 Web 服务器肯定会。

回答by Tony Sepia

I have just experienced exactly the same problem. Contrary to the most upvoted answer, the issue has a lot to do with Python and Flask, and it is not a Windows issue. Very easy to reproduce:

我刚刚遇到了完全相同的问题。与最受好评的答案相反,该问题与 Python 和 Flask 有很大关系,而不是 Windows 问题。很容易重现:

  • Click on a link within a flask application and then navigate to another page whilst the first one is still loading. Error appears every time and application crashes (needs restarting)
  • The issue never happens if I allow the server to return the page completely.
  • 单击 Flask 应用程序中的链接,然后在第一个页面仍在加载时导航到另一个页面。每次都出现错误并且应用程序崩溃(需要重新启动)
  • 如果我允许服务器完全返回页面,则问题永远不会发生。

Also, this has never happened with bottle micro-framework, for example.

此外,例如,瓶子微框架从未发生过这种情况。

If I find out how to solve the problem I will let you know

如果我知道如何解决问题,我会让你知道

回答by Keyur

Hello,This is an issue with the Python 2 implementation of the SocketServer module, it is not present in Python 3 (where the server keeps on serving).

您好,这是 SocketServer 模块的 Python 2 实现的一个问题,它不存在于 Python 3(服务器继续提供服务)中。

Your have 3 options:

Don't use the built-in server for production systems (it is a development server after all). Use a proper WSGI server like gunicorn or uWSGI.

Enable threaded mode with app.run(threaded=True); the thread dies but a new one is created for future requests,

Upgrade to Python 3.

您有 3 个选择:

不要将内置服务器用于生产系统(毕竟它是一个开发服务器)。使用合适的 WSGI 服务器,如 gunicorn 或 uWSGI。

使用 app.run(threaded=True) 启用线程模式;线程死了,但为将来的请求创建了一个新线程,

升级到 Python 3。

So whenever there is error like

所以每当出现错误时

error: [Errno 10053] An established connection was aborted by the software in your host machine

Server would be restarted if you have done like app.run(threaded=True).

如果您像 app.run(threaded=True) 那样完成,服务器将重新启动。

回答by rob_7cc

This error can occur regardless of Flask, Python 2, Python 3, or HTTP -- it can occur simply at the socket level and it will depend heavily on your exact situation.

无论使用 Flask、Python 2、Python 3 还是 HTTP,都可能发生此错误——它可能仅发生在套接字级别,并且在很大程度上取决于您的具体情况。

As an example, my application uses an Ethernet device/appliance that uses raw sockets for command and control and I am using the create_connectionmethod in the socketmodule. I would consistently get "Errno 10053" after trying to send a message after a period of traffic inactivity. Timing tests showed that this error would occur after trying to send a message after four minutes of inactivity. The following page indicates a 240 second = 4min timeout:

例如,我的应用程序使用使用原始套接字进行命令和控制的以太网设备/电器,并且我正在使用模块中的create_connection方法socket。在一段时间的流量不活动后尝试发送消息后,我会一直收到“Errno 10053”。计时测试表明,在四分钟不活动后尝试发送消息后会发生此错误。以下页面指示 240 秒 = 4 分钟超时:

https://support.microsoft.com/en-us/help/170359/how-to-modify-the-tcp-ip-maximum-retransmission-time-out

https://support.microsoft.com/en-us/help/170359/how-to-modify-the-tcp-ip-maximum-retransmission-time-out

The solution in my scenario was to ensure that messages to the device did not span more than four minutes. I simply send a small request message to the device every 60sec to avoid the 10053 error -- this acts as a protocol-level "keep-alive" (unrelated to TCP keepalive). In this scenario, perhaps the issue is specific to the Ethernet device and the way they've implemented TCP. Nonetheless, a protocol-level "keep-alive" may be a viable option in many cases.

我的方案中的解决方案是确保发送到设备的消息不超过四分钟。我只是每 60 秒向设备发送一个小请求消息,以避免 10053 错误——这充当协议级别的“保持活动”(与 TCP 保持活动无关)。在这种情况下,问题可能与以太网设备及其实现 TCP 的方式有关。尽管如此,在许多情况下,协议级别的“保持活动”可能是一个可行的选择。