python - SimpleHTTPServer - 服务大文件

标签 python http simplehttpserver

我正在使用 python -m SimpleHTTPServer对于一个小项目。文件 index.html 引用了一些视频。 <video><source src="big_buck_bunny_480p_stereo.ogg"></video> 此文件的大小为 159 MB。当我尝试下载它时,SimpleHTTPServer 抛出一些错误消息而不是我的视频。

Marc-Laptop - - [23/Sep/2012 18:18:29] "GET /big_buck_bunny_480p_stereo.ogg HTTP
/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.4.38', 51152)
Traceback (most recent call last):
  File "C:Program Files (x86)PythonlibSocketServer.py", line 284, in _handle
_request_noblock
    self.process_request(request, client_address)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 310, in process
_request
    self.finish_request(request, client_address)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 323, in finish_
request
    self.RequestHandlerClass(request, client_address, self)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 640, in __init_
_
    self.finish()
  File "C:Program Files (x86)PythonlibSocketServer.py", line 693, in finish
    self.wfile.flush()
  File "C:Program Files (x86)Pythonlibsocket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen

----------------------------------------

最佳答案

simpleHTTPServer 正在尝试缓冲所有内容,并且确实会因内存不足而爆炸。最好异步执行,但 simpleHTTPServer 不知道如何执行。检查 thread .有人提出了 simpleHTTPserver 的修改版本:SimpleAsyncHTTPServer.py

关于python - SimpleHTTPServer - 服务大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12554021/

相关文章:

python - 更改 pandas DataFrame 中的特定列名

Python 请求库的 Ruby 等价物(HTTP 客户端)

http - REST url 中的动词

python - 从 SocketServer.ForkingTCPServer python 释放套接字

python - 使用 BaseHTTPRequestHandler 从 POST 请求接收二进制文件

python - 使用 django 1.8 持续时间字段注释一组 django 对象

python - 从表单获取数据,但根据 Flask 所在的页面运行函数

python - AES CTR 实现

http - 在服务器代码中处理强制性 SSL

Python SimpleHTTPServer 404 页面