Flask:服务器在一段时间后变得没有响应

时间:2014-09-03 10:20:32

标签: python ubuntu flask

我使用烧瓶服务器从服务器提供静态文件,但有时服务器完全没有响应,下载文件会继续加载但从不下载。当我打开终端时,我发现了一些奇怪的请求,我点击了CTRL + C,服务器立即再次响应并继续下载。这种情况经常发生,我不知道是什么导致这种情况以及如何防止它冻结我的烧瓶服务器,这个人是否试图破解?

user@server:~/worker# python server.py
 * Running on http://0.0.0.0:80/
93.134.13.318 - - [03/Sep/2014 02:07:18] code 400, message Bad request syntax ('\x00')
93.134.13.318 - - [03/Sep/2014 02:07:18] "" 400 -
93.134.13.318 - - [03/Sep/2014 02:07:19] "GET http://httpheader.net HTTP/1.1" 404 -
93.134.13.318 - - [03/Sep/2014 02:07:40] code 400, message Bad request syntax ('\x04\x01\x00P\xc6\xce\x0eu0\x00')
93.174.93.218 - - [03/Sep/2014 02:07:40] "P��u0" 400 -
^C----------------------------------------
Exception happened during processing of request from ('93.174.93.218 ', 45082)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 200, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 231, in handle_one_request
    self.raw_requestline = self.rfile.readline()
  File "/usr/lib/python2.7/socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
----------------------------------------
42.36.63.90 - - [03/Sep/2014 03:21:20] "GET / HTTP/1.1" 404 -
63.63.193.195 - - [03/Sep/2014 03:21:20] "GET / HTTP/1.1" 404 -

1 个答案:

答案 0 :(得分:3)

我有同样的问题。 django / flask应用程序在作为python server.py运行时挂起很常见,因为这不适合它们。仅用于测试目的。当你完成它并想要发布时,你应该把它放在wsgi / uwsgi + apache / nginx后面,你的问题就会消失。

<德尔> http://flask.pocoo.org/docs/0.10/deploying/uwsgi/

http://flask.pocoo.org/docs/1.0/deploying/uwsgi/