You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Django调试时出现WinError 10054连接重置错误求助

解决Django开发服务器的ConnectionResetError及后续异常问题

Hey there, let's break down this issue you're facing. The root cause starts with the ConnectionResetError: [WinError 10054] — this happens when the remote client (your browser) forcibly closes the connection before the server finishes sending the response. The follow-up errors like TypeError: 'NoneType' object is not subscriptable and AttributeError: 'NoneType' object has no attribute 'split' are secondary issues, triggered when the wsgiref handler tries to clean up after the broken connection but hits uninitialized variables.

Here are actionable fixes to try, ordered from simplest to more involved:

  • Verify your favicon file and static configuration
    The error occurs when requesting /static/node_modules/metronic-theme-classic/assets/media/logos/favicon.ico. First, confirm this file actually exists at that path in your project. Double-check your Django STATIC_URL, STATIC_ROOT, and STATICFILES_DIRS settings to ensure the server is correctly serving static files from the node_modules directory. You can test accessing other static files to rule out general static serving issues.

  • Test without automatic favicon requests
    Browsers often auto-request favicons in the background. Try using a tool like curl to send a request to a different page (e.g., curl http://127.0.0.1:8000/) and see if the error persists. If it doesn't, the issue might be specific to how your browser is handling the favicon request.

  • Upgrade Python and Django versions
    You're using Python 3.6, which is no longer supported, and likely an older Django version. Both Python's wsgiref module and Django have fixed several connection-handling bugs in newer releases. Upgrade to a supported Python version (3.8 or later) and a compatible Django version (e.g., Django 3.2+ for Python 3.8) — this often resolves low-level network issues like this.

  • Adjust Django dev server settings
    Try running the server with the --noreload flag:

    python manage.py runserver --noreload
    

    The auto-reload mechanism can sometimes cause unstable connections. You can also temporarily set DEBUG=False in your settings (remember to set ALLOWED_HOSTS properly) to see if the error goes away, as debug mode changes how the server handles errors.

  • Check Windows security tools
    WinError 10054 can also be triggered by Windows Firewall or third-party antivirus software blocking or resetting the connection. Temporarily disable these tools (with caution) and test the server again to rule out this possibility.

Full Error Traceback

Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers self.send_preamble() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 258, in send_preamble self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1')) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write self._sock.sendall(b) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host [19/Apr/2019 14:31:19] ERROR [django.server:154] "GET /static/node_modules/metronic-theme-classic/assets/media/logos/favicon.ico HTTP/1.1" 500 59 ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 52183) Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers self.send_preamble() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 258, in send_preamble self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1')) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write self._sock.sendall(b) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 141, in run self.handle_error() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error super().handle_error() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 368, in handle_error self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 331, in send_headers if not self.origin_server or self.client_is_modern(): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9' TypeError: 'NoneType' object is not subscriptable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread self.finish_request(request, client_address) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__ self.handle() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle self.handle_one_request() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request handler.run(self.server.get_app()) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 144, in run self.close() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 111, in close super().close() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\simple_server.py", line 35, in close self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split' ---------------------------------------- Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 333, in send_headers self._write(bytes(self.headers)) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write self._sock.sendall(b) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host [19/Apr/2019 14:31:21] ERROR [django.server:154] "GET /static/node_modules/metronic-theme-classic/assets/media/logos/favicon.ico HTTP/1.1" 500 59 ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 52185) Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 333, in send_headers self._write(bytes(self.headers)) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write self._sock.sendall(b) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 141, in run self.handle_error() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error super().handle_error() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 368, in handle_error self.finish_response() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write self.send_headers() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 331, in send_headers if not self.origin_server or self.client_is_modern(): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9' TypeError: 'NoneType' object is not subscriptable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread self.finish_request(request, client_address) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__ self.handle() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle self.handle_one_request() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request handler.run(self.server.get_app()) File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 144, in run self.close() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 111, in close super().close() File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\simple_server.py", line 35, in close self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split'

内容的提问来源于stack exchange,提问作者Saiful Azad

火山引擎 最新活动