python - 使用 Flask、gunicorn、docker 和 azure 处理请求时出现套接字错误

标签 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

最佳答案

最后,我发现这是由 pod liveness 探针引起的,因为gunicorn 服务器目前无法同时支持 http 和 https,如果我们仅将 https 用于公共(public)域,则 http 探针检查请求将失败这个错误。

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

关于python - 使用 Flask、gunicorn、docker 和 azure 处理请求时出现套接字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51619559/

相关文章:

azure - 我为我的特定 Azure 应用程序启用了 MFA。第一次登录 Azure 的用户,为这些用户启用 MFA。如何为所有现有用户启用 MFA?

azure - 限制 Azure Function 只能从一个域调用

windows - 在 server core 2019ltsc 容器镜像中添加字体

asp.net - 在 Elastic Beanstalk 上访问 Dockerized ASP.NET Core Web API 时出现 502 Bad Gateway

python - 启动 python 进行 Web 开发的好资源?

python - 如何在多台计算机之间共享文件

node.js - React Fetch() 我的本地 Node Express 后端;无法返回后端测试值

ruby-on-rails - 如何减小docker镜像大小?

python - 在pyspark中创建两个时间戳之间的时间戳数组

Python:在没有剪贴板的情况下从 Office/Excel 文档访问嵌入式 OLE