【问题标题】:Django - Leaving socket open while receiving dataDjango - 在接收数据时保持套接字打开
【发布时间】:2016-03-14 02:33:53
【问题描述】:

当我尝试加载较大 (50mb) 的视频时,服务器会抛出此错误:

[14/Mar/2016 02:16:13] "GET /media/media/uploads/SampleVideo_1280x720_50mb.mp4 HTTP/1.1" 200 52464391
[14/Mar/2016 02:16:13] "GET /media/media/uploads/SampleVideo_1280x720_50mb.mp4 HTTP/1.1" 200 286720
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 128, in finish_response
    self.write(data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 217, in write
    self._write(data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 328, in write
    self.flush()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 307, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 41] Protocol wrong type for socket
[14/Mar/2016 02:16:13] "GET /media/media/uploads/SampleVideo_1280x720_50mb.mp4 HTTP/1.1" 500 59
- Broken pipe from ('127.0.0.1', 52070)

如您所见,在引发错误之前,该视频被请求了两次。这似乎是在加载整个视频之前套接字关闭时引起的。小视频不会引发错误这一事实也支持这一点(在 Chrome 上 - 一切都在 Safari 上引发错误)

我在开发服务器中使用 django 1.9 和 html5 将视频显示到页面上。

在收到所有数据包之前,我如何才能保持套接字打开?为什么这甚至会成为默认行为?我想不出在发送所有必需数据之前关闭套接字的任何有用应用。

【问题讨论】:

    标签: python django html sockets


    【解决方案1】:

    使用 AWS S3 存储和处理媒体此问题已在所有浏览器上得到修复。一定和开发服务器有关。

    【讨论】:

      猜你喜欢
      • 2017-09-28
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      相关资源
      最近更新 更多