2

I got error when i perform ajax request. Without authentication lines user = authenticate(username = user_username, password = user_password) in the views.py, success function is called. And if i add, error function is called with Errno 10053.

I am using MySql in Wamp. Why it is happening ? 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 request:

$(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)

Please explain where i made the mistake and why it is happening.

Thanks in advance !!

Wickkiey
  • 4,446
  • 2
  • 39
  • 46
  • 1
    This error would basically mean you tried to send response to the requester who is no more requesting it. There would have been a timeout or some other network break scenario. – Nagaraj Tantri Apr 19 '15 at 06:11
  • @LearningNeverStops I tried restartring wamp. How can i catch this exceptions ? – Wickkiey Apr 19 '15 at 06:25
  • these kinds of error is not something generated for catching, is this error actually making any shutdown of sever? I don't think so. Could please confirm on the same? As much as I can say, the only thing that would happen is it would silently ignore the error. And its not happening w.r.t to your username authentication but with Httpresponse return value. – Nagaraj Tantri Apr 20 '15 at 03:44

2 Answers2

1

Reference: https://stackoverflow.com/a/17854758/3940406

From the Windows Sockets Error Codes list:

WSAECONNABORTED 10053 Software caused connection abort. An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error.

There was a timeout or other network-level error. This is your operating system closing the socket, nothing to do with Python, django or Flask, really.

It could be the remote browser stopped responding, the network connection died, or a firewall closed the connection because it was open too long, or any other number of reasons.

Abhishake Gupta
  • 2,939
  • 1
  • 25
  • 34
0

I came by the question when I was trying to research a problem with regards to running a mysql code using the pymysql as the python sql client. I happen to have this same issue. Renaming the config setting for mysql and then restarting your system or running mysql server. Works to fix this issue

Torch
  • 51
  • 1
  • 9