Django:错误:[Errno 10053]已建立的连接被主机中的软件中止

时间:2015-04-19 06:02:02

标签: ajax django django-views

我执行ajax请求时遇到错误。如果没有views.py中的身份验证行user = authenticate(username = user_username, password = user_password),则会调用success函数。如果我添加,则使用Errno 10053调用错误函数。

我在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");
             }

         });
     });

Tracebrack

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)

请解释我犯错的地方以及发生的原因。

提前致谢!!

1 个答案:

答案 0 :(得分:0)

参考:https://stackoverflow.com/a/17854758/3940406

从Windows套接字错误代码列表中:

  

WSAECONNABORTED 10053软件导致连接中止。已建立   连接被主机计算机中的软件中止了   由于数据传输超时或协议错误。

存在超时或其他网络级错误。实际上,这是您的操作系统正在关闭套接字,与Python,django或Flask无关。

可能是远程浏览器停止响应,网络连接中断或防火墙由于打开时间太长而关闭了连接,或其他多种原因。