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



我在执行 ajax 请求时出错。如果没有 views.py 中user = authenticate(username = user_username, password = user_password)身份验证行,则调用成功函数。如果我添加,则使用 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')

阿贾克斯请求:

$(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:Python27libwsgirefhandlers.py", line 86, in run
    self.finish_response()
  File "C:Python27libwsgirefhandlers.py", line 127, in finish_response
    self.write(data)
  File "C:Python27libwsgirefhandlers.py", line 210, in write
    self.send_headers()
  File "C:Python27libwsgirefhandlers.py", line 268, in send_headers
    self.send_preamble()
  File "C:Python27libwsgirefhandlers.py", line 192, in send_preamble
    'Date: %srn' % format_date_time(time.time())
  File "C:Python27libsocket.py", line 324, in write
    self.flush()
  File "C:Python27libsocket.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:Python27libSocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "C:Python27libSocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:Python27libsite-packagesdjango-1.7-py2.7.eggdjangocoreserversbasehttp.py", line 129, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "C:Python27libSocketServer.py", line 640, in __init__
    self.finish()
  File "C:Python27libSocketServer.py", line 693, in finish
    self.wfile.flush()
  File "C:Python27libsocket.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)

请解释我在哪里犯了错误以及为什么会发生错误。

提前感谢!!

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

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

WSAECONNABORED 10053 软件导致连接中止。一个已建立的 主机中的软件中止了连接,可能是 由于数据传输超时或协议错误。

出现超时或其他网络级错误。这是你的操作系统关闭套接字,与Python,django或Flask无关,真的。

可能是远程浏览器停止响应、网络连接死亡或防火墙因打开时间过长而关闭连接或任何其他原因。

当我试图研究有关使用 pymysql 作为 python sql 客户端运行 mysql 代码的问题时,我遇到了这个问题。我碰巧有同样的问题。重命名 mysql 的配置设置,然后重新启动系统或运行 mysql 服务器。致力于解决此问题

最新更新