当前位置: 代码迷 >> 综合 >> Django ConnectionAbortedError: [WinError 10053]错误
  详细解决方案

Django ConnectionAbortedError: [WinError 10053]错误

热度:40   发布时间:2023-12-03 11:56:49.0

这两天遇到个非常坑爹的错误,我各种方法都试了甚至到了最后一步重做系统还是出现这个问题,几乎绝望,这个错误如下:

Traceback (most recent call last):File "E:\python\lib\wsgiref\handlers.py", line 138, in runself.finish_response()File "E:\python\lib\wsgiref\handlers.py", line 180, in finish_responseself.write(data)File "E:\python\lib\wsgiref\handlers.py", line 274, in writeself.send_headers()File "E:\python\lib\wsgiref\handlers.py", line 332, in send_headersself.send_preamble()File "E:\python\lib\wsgiref\handlers.py", line 255, in send_preamble('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')File "E:\python\lib\wsgiref\handlers.py", line 453, in _writeresult = self.stdout.write(data)File "E:\python\lib\socketserver.py", line 775, in writeself._sock.sendall(b)
[11/Apr/2018 20:17:19]"GET /static/js/rev.js HTTP/1.1" 304 0
ConnectionAbortedError: [WinError 10053] 您的主机中的软件中止了一个已建立的连接。
[11/Apr/2018 20:17:19]"POST /revright/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53550)
Traceback (most recent call last):File "E:\python\lib\wsgiref\handlers.py", line 138, in runself.finish_response()File "E:\python\lib\wsgiref\handlers.py", line 180, in finish_responseself.write(data)File "E:\python\lib\wsgiref\handlers.py", line 274, in writeself.send_headers()File "E:\python\lib\wsgiref\handlers.py", line 332, in send_headersself.send_preamble()File "E:\python\lib\wsgiref\handlers.py", line 255, in send_preamble('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')File "E:\python\lib\wsgiref\handlers.py", line 453, in _writeresult = self.stdout.write(data)File "E:\python\lib\socketserver.py", line 775, in writeself._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] 您的主机中的软件中止了一个已建立的连接。During handling of the above exception, another exception occurred:Traceback (most recent call last):File "E:\python\lib\wsgiref\handlers.py", line 141, in runself.handle_error()File "E:\python\lib\site-packages\django\core\servers\basehttp.py", line 95, in handle_errorsuper(ServerHandler, self).handle_error()File "E:\python\lib\wsgiref\handlers.py", line 368, in handle_errorself.finish_response()File "E:\python\lib\wsgiref\handlers.py", line 180, in finish_responseself.write(data)File "E:\python\lib\wsgiref\handlers.py", line 274, in writeself.send_headers()File "E:\python\lib\wsgiref\handlers.py", line 331, in send_headersif not self.origin_server or self.client_is_modern():File "E:\python\lib\wsgiref\handlers.py", line 344, in client_is_modernreturn self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptableDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "E:\python\lib\socketserver.py", line 639, in process_request_threadself.finish_request(request, client_address)File "E:\python\lib\socketserver.py", line 361, in finish_requestself.RequestHandlerClass(request, client_address, self)File "E:\python\lib\site-packages\django\core\servers\basehttp.py", line 102, in __init__super(WSGIRequestHandler, self).__init__(*args, **kwargs)File "E:\python\lib\socketserver.py", line 696, in __init__self.handle()File "E:\python\lib\site-packages\django\core\servers\basehttp.py", line 182, in handlehandler.run(self.server.get_app())File "E:\python\lib\wsgiref\handlers.py", line 144, in runself.close()File "E:\python\lib\wsgiref\simple_server.py", line 35, in closeself.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

js代码如下:

$.post('http://127.0.0.1:8000/revright/', {id : id}, function(data){
    alert(data)
})

千辛万苦才找到这个错误的原因:

因为ajax默认是异步提交,可是有时候我们会发现,本来要求请求马上出现,可是异步会导致后面突然再执行,这样就出问题了。
如下两种解决方案:

(1)添加这样一段代码

$.ajaxSetup({async : false });

(2)或者这样

$.ajax({  type : "post", url : "http://127.0.0.1:8000/revright/",  data : data, async : false,  success : function(data){ alert(data) } });