Ajax Django:错误:[Errno 10053]主机中的软件中止了已建立的连接
我在执行ajax请求时出错。在views.py中没有身份验证行Ajax Django:错误:[Errno 10053]主机中的软件中止了已建立的连接,ajax,django,django-views,Ajax,Django,Django Views,我在执行ajax请求时出错。在views.py中没有身份验证行user=authenticate(username=user\u username,password=user\u password),则调用success函数。如果我加上,就会用Errno 10053调用error函数 我在Wamp中使用MySql。为什么会这样? views.py class LoginVerify(View): print('login') def post(self,request,*arg
user=authenticate(username=user\u username,password=user\u password)
,则调用success函数。如果我加上,就会用Errno 10053调用error函数
我在Wamp中使用MySql。为什么会这样?
views.py
class LoginVerify(View):
print('login')
def post(self,request,*args,**kwargs):
if request.is_ajax():
print("post called")
user_email = request.POST.get('email',False)
user_password = request.POST.get('pswd',False)
print(user_email)
try:
user_username = User.objects.get(email=user_email).username
user = authenticate(username = user_username, password = user_password)
except:
print("error occured")
return HttpResponse("response form server")
def get(self, request,*args,**kwargs):
print("get method")
return render(request,'feeds/feeds_home.html')
ajax请求:
$(document).ready(function(){
$("#submit").on("click",function(){
var $email = $("#signin-email").val();
var $pswd = $("#signin-password").val();
alert($pswd);
$.ajax({
url : '{% url "feeds:login_view" %}',
type: "POST",
data: {csrfmiddlewaretoken :"{{ csrf_token }}", pswd : $pswd, email: $email},
success: function(data){
location.reload();
},
error: function(){
alert("fails");
}
});
});
痕迹
post called
vivek.ananthan.m.s@gmail.com
[19/Apr/2015 11:10:22] "POST / HTTP/1.1" 200 12
Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\handlers.py", line 86, in run
self.finish_response()
File "C:\Python27\lib\wsgiref\handlers.py", line 127, in finish_response
self.write(data)
File "C:\Python27\lib\wsgiref\handlers.py", line 210, in write
self.send_headers()
File "C:\Python27\lib\wsgiref\handlers.py", line 268, in send_headers
self.send_preamble()
File "C:\Python27\lib\wsgiref\handlers.py", line 192, in send_preamble
'Date: %s\r\n' % format_date_time(time.time())
File "C:\Python27\lib\socket.py", line 324, in write
self.flush()
File "C:\Python27\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\site-packages\django-1.7-py2.7.egg\django\core\servers\basehttp.py", line 129, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "C:\Python27\lib\SocketServer.py", line 640, in __init__
self.finish()
File "C:\Python27\lib\SocketServer.py", line 693, in finish
self.wfile.flush()
File "C:\Python27\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52490)
请解释我在哪里犯的错误以及为什么会发生
提前谢谢 参考:
从Windows套接字错误代码列表中:
WSAECONNABORTED 10053软件导致连接中止。既定的
可能是主机中的软件中止了连接
由于数据传输超时或协议错误
出现超时或其他网络级错误。这是您的操作系统关闭套接字,与Python、django或Flask无关,真的
可能是远程浏览器停止响应、网络连接中断、防火墙关闭连接(因为连接打开时间过长)或其他原因。此错误基本上意味着您试图向不再请求响应的请求者发送响应。可能会出现超时或其他网络中断情况。@LearningNeverStops我尝试重新启动wamp。我如何捕捉这些异常?这些类型的错误不是为了捕捉而生成的,这个错误是否真的导致服务器关闭?我不这么认为。请确认一下?正如我所能说的,唯一会发生的事情就是它会默默地忽略错误。并且它不会对您的用户名进行w.r.t身份验证,而是使用Httpresponse返回值。