Solution 1 :

What you see is an error from your local Django “runserver” when it’s interrupted while serving a big file. Django isn’t really made for serving static files, so you get this error indeed when you navigate to a different page and your browser interrupts the video stream.

This shouldn’t be something to worry about in production: Your video will be served by S3 or preferably a CDN that you add to the mix. Those won’t have issues when the stream is interrupted (or at least you won’t have to worry about it and won’t see this in your logs). Django isn’t involved at all in this case.

If this hampers your development flow, you might want to suppress these errors from your development logging by adding a filter to your logs (just in development).

Problem :

I’m having a Django project, where a FileField is applied for storing a video file (mp4).
The Video File is actually stored on AmazonS3.

The video file is then showed on the corresponding HTML, though Django DetailView, with an HTML5 video tag.

<video width='50%' controls>
<source src="{{ object.video_sample.url }}" type="video/mp4">
    Your browser does not support the video tag.

The video is played well both locally (local ip) on and on deployed server.
However, I’m keep getting this annoying error message on terminal/logs:

Exception happened during processing of request from (…)
Traceback (most recent call last):
File “/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/”, line 650, in process_request_thread
self.finish_request(request, client_address)
File “/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/”, line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File “/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/”, line 720, in init
File “…/env/lib/python3.7/site-packages/django/core/servers/”, line 171, in handle
File “…/env/lib/python3.7/site-packages/django/core/servers/”, line 179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File “/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/”, line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer*

I think that it related with the fact user leaves the HTML page while the video is still open.

Do you know how to get it resolved?



Comment posted by dirkgroten

This error message is locally, right, in development mode? If the video is served from S3 then you won’t get this error since S3 would see the connection interrupted, not your Django instance.

Comment posted by Shahar Gino

Yes, correct. Do you know how to overcome it?

Comment posted by dirkgroten

No reason to overcome it, it’s normal. In development, your video is served by Django (runserver) but Django isn’t really made for serving static files, especially not long video streams. In production, your video will be served by S3 (or a CDN if you add that to the mix) and you won’t see this issue.

Comment posted by Shahar Gino

Excellent, got it, thank you very much!