30
FFS… so dumb. I noticed that it was always resetting after not finding a favicon so I added one… Even though I never explicitly loaded one, django appears to try and load a default one from the root of the project… This doesn’t happen for any of the other devs working on the project either. weird.
(For completeness) If anyone else stumbles upon this i used favicon io to make a simple text one. Then i loaded it into my html like so:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" href="{% static 'images/favicon.ico' %}" />
...
Be sure to set your static path correctly in settings.
12
The same behaviour is seen if the favicon is in .png format as opposed to .ico.
Also, contrary to advice seen on other sites, downgrading Python to v3.6 does not solve the problem. screenshot of error w. png favicon
Seems to be a Django issue, It will probably be fixed permanently in a future Django release.
Following https://bugs.python.org/issue27682#msg348302 I made the changes shown:
I then replaced BrokenPipeError with ConnectionAbortedError. This seems to handle the exception.
Update for Django 3: I have the following changes in basehttp.py (rev.1.2.1) to get rid of all the pesky broken pipe error messages:
Line 55: - return issubclass(exc_type, BrokenPipeError)
Line 55: + return issubclass(exc_type, (BrokenPipeError, ConnectionAbortedError, ConnectionResetError))
Line 71: - logger.info("- Broken pipe from %s\n", client_address)
Line 71: + pass
- [Django]-ImageField overwrite image file with same name
- [Django]-Cannot resolve 'django.utils.log.NullHandler' in Django 1.9+
- [Django]-Django ManyToMany filter()
1
I came across the same issue ConnectionResetError: [Errno 54] Connection reset by peer
.
In my case the issue was trying to serve static files through development server with debug settings to False
, development server can serve static files only when debug
is set to True
in settings file.
In my settings file i replace
DEBUG = False
with
DEBUG = True
After that, I restart my development server and it works for me!
- [Django]-Prompt file download with XMLHttpRequest
- [Django]-How do I get the class of a object within a Django template?
- [Django]-Difference between different ways to create celery task
1
None of the current answers worked for me. This is how I made the error go away during development on MacOS for Django 3 (untested on other versions).
Create a custom runserver management command in one of your project apps which is only different when DEBUG==True
and you are on a Mac. Pay particular attention to Command.get_handler
:
#myapp/management/commands/runserver.py
import platform
import django.core.servers.basehttp
from django.conf import settings
from django.contrib.staticfiles.management.commands.runserver import Command as RunserverCommand
from django.core.servers.basehttp import ServerHandler
def handle_one_request(self):
"""
Exact copy of django.core.servers.WSGIRequestHandler.handle_one_request except it
Completely ignores "ConnectionResetError: [Errno 54] Connection reset by peer"
Which seems to be only noise on MacOS.
"""
try:
self.raw_requestline = self.rfile.readline(65537)
except ConnectionResetError:
return
if len(self.raw_requestline) > 65536:
self.requestline = ""
self.request_version = ""
self.command = ""
self.send_error(414)
return
if not self.parse_request(): # An error code has been sent, just exit
return
handler = ServerHandler(self.rfile, self.wfile, self.get_stderr(), self.get_environ())
handler.request_handler = self # backpointer for logging & connection closing
handler.run(self.server.get_app())
class Command(RunserverCommand):
def get_handler(self, *args, **options):
if settings.DEBUG and platform.platform().upper().startswith("DARWIN"):
# patch the offending code
django.core.servers.basehttp.WSGIRequestHandler.handle_one_request.__code__ = handle_one_request.__code__
return super().get_handler(*args, **options)
And add your app to INSTALLED_APPS
above the django.contrib.staticfiles
:
INSTALLED_APPS = [
. . .
"myapp",
"django.contrib.staticfiles",
. . .
]
- [Django]-AttributeError: module Django.contrib.auth.views has no attribute
- [Django]-How does Django Know the Order to Render Form Fields?
- [Django]-Distributing Django projects with unique SECRET_KEYs
0
I also encountered this issue when i switch from development to production.
After i do collectstatic it worked normal again, my guess is it’s missing static dir path for production
do this before you switch to production environment
python manage.py collectstatic
- [Django]-ERROR: Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects
- [Django]-What is a django.utils.functional.__proxy__ object and what it helps with?
- [Django]-Object has no attribute 'get'
0
I had the same issue in my project. Maybe this post can help someone.
In my case the problem was I call the function from the button with onclick
like this:
<a class="btn btn-warning" onclick="submitData();">Caption</a>
I changed this to a better way:
<button class="btn btn-warning" id="button-action">Caption</button>
And then handle the click:
document.getElementById('button-action').addEventListener('click', function(e){
submitData()
})
- [Django]-How to expire session due to inactivity in Django?
- [Django]-What is the advantage of Class-Based views?
- [Django]-Django and query string parameters