0

I am having an issue with my Flask API and i don't know why. From time to time i have this socket error :

  Exception happened during processing of request from ('127.0.0.1', 52558)
  Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 295, in_handle_request_noblock
  self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 321, in process_request
  self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
  self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 657, in __init__
  self.finish()
  File "C:\Python27\lib\SocketServer.py", line 716, in finish
  self.wfile.close()
  File "C:\Python27\lib\socket.py", line 283, in close
  self.flush()
  File "C:\Python27\lib\socket.py", line 307, in flush
  self._sock.sendall(view[write_offset:write_offset+buffer_size])
  [Error 10053] An established connection was aborted by the software in your host machine. 

While i am trying to do the following :

  @app.route('/api/gener/', methods=['GET'])
  def gener():
   seed = 123    # seed for random generation
   Lambda = 100    # rate of demands
   alpha = 1.1   # decay factor for Zipf
   N = 100     # catalog size
   NB_demands = 200  # number of demands
   list = generate_demand(Lambda, alpha, N, NB_demands, seed)
   timee = 0

   for i in list:
    a = Content1.query.filter_by(id = i[1])
    filename = a[0].name
    time.sleep(i[0]-timee)
    visit = visits1(name=filename)
    db.session.add(visit)
    a[0].Hits += 1
    timee = i[0]
   db.session.commit()   
   return " Requests sent successfully"

Can someone please help!

Rzozi
  • 127
  • 1
  • 2
  • 9
  • The client stopped the request because it time out or the user clicked stop. It might be related to the `sleep()` calls in your view. They should not be used in processing web requests. – Klaus D. Mar 23 '16 at 15:03
  • I suspected the same thing at the beginning, so i removed the `sleep()` calls for the view and still get the same error.The weird thing is that the error does not happen all the time. – Rzozi Mar 23 '16 at 15:10
  • How long does it actually take to execute the view? – Klaus D. Mar 23 '16 at 15:11
  • normaly 3 seconds, when the error occurs the view is executed twice. – Rzozi Mar 23 '16 at 15:17
  • Can it be related to the OS, i am using Win7 ? – Rzozi Mar 23 '16 at 15:19
  • That's rather long. Also it's not a good idea to overload the built-in `list`. – Klaus D. Mar 23 '16 at 15:20
  • and what do you suggest to do in this case ? – Rzozi Mar 23 '16 at 15:30
  • Choose an other name than `list` and for the main problem: you should process the request in an other process. Just write the request data to the database, return a 202 and have an other process collect the job. For larger scale systems there are solutions like celery. – Klaus D. Mar 23 '16 at 15:36
  • Ok i will try this, thank you – Rzozi Mar 23 '16 at 15:38
  • Possible duplicate of [Flask - socket.error: \[Errno 10053\] An established connection was aborted by the software in your host machine](https://stackoverflow.com/questions/40247025/flask-socket-error-errno-10053-an-established-connection-was-aborted-by-the) – Rob Aug 01 '17 at 02:31

0 Answers0