使用Flask,Gunicorn,Docker和Azure的套接字错误处理请求

时间:2018-07-31 18:08:16

标签: python azure docker flask gunicorn

运行带有gunicorn的python flask应用程序。当我在本地启动docker映像时,一切都很好,但是当我使用kubernetes在Azure上运行docker映像时,出现此OSError。该请求很好,但是在日志中出现错误。

现在有人在发生什么事吗?

10.242.0.1 - - [31/Jul/2018:15:11:04 +0000] "GET /api/evaluation HTTP/1.1" 200 14343  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
[2018-07-31 15:11:05 +0000] [10] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 134, in handle
    req = six.next(parser)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/parser.py", line 41, in __next__
    self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 181, in __init__
    super(Request, self).__init__(cfg, unreader)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 54, in __init__
    unused = self.parse(self.unreader)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 193, in parse
    self.get_data(unreader, buf, stop=True)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 184, in get_data
    data = unreader.read()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/unreader.py", line 38, in read
    d = self.chunk()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/unreader.py", line 65, in chunk
    return self.sock.recv(self.mxchunk)
  File "/usr/local/lib/python3.6/ssl.py", line 994, in recv
    return self.read(buflen)
  File "/usr/local/lib/python3.6/ssl.py", line 871, in read
    return self._sslobj.read(len, buffer)
  File "/usr/local/lib/python3.6/ssl.py", line 633, in read
    v = self._sslobj.read(len)
OSError: [Errno 0] Error

通过以下方式启动应用

gunicorn --certfile Config/cert.crt --keyfile Config/cert.key -w 2 -b :8084 --access-logfile - gunicorn_app:app

3 个答案:

答案 0 :(得分:1)

最后,我发现这是由于Pod liveness探测器引起的,因为gunicorn服务器当前无法同时支持http和https,并且如果我们仅对公共域使用https,并且http探测器检查请求将失败这个错误。

解决方案: 将gunicorn服务器更改为Nginx或Apache。

答案 1 :(得分:0)

将python版本从3.6。*升级到3.7.4,效果很好。

答案 2 :(得分:0)

我已经从金枪鱼变成了uwsgi,不再头痛!