首页 > 解决方案 > 使用 gunicorn 部署烧瓶应用程序会引发 OSError:[Errno 0] 错误

问题描述

每次使用 gunicorn 部署烧瓶应用程序都会抛出异常OSError: [Errno 0] Error

下面是错误:

[2021-06-28 12:00:21 +0000] [11] [ERROR] Socket error processing request.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/sync.py", line 135, in handle
req = next(parser)
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/parser.py", line 42, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.source_addr, self.req_count)
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/message.py", line 180, in __init__
super().__init__(cfg, unreader, peer_addr)
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/message.py", line 54, in __init__
unused = self.parse(self.unreader)
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/message.py", line 192, in parse
self.get_data(unreader, buf, stop=True)
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/message.py", line 183, in get_data
data = unreader.read()
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/unreader.py", line 37, in read
d = self.chunk()
File "/usr/local/lib/python3.8/dist-packages/gunicorn/http/unreader.py", line 64, in chunk
return self.sock.recv(self.mxchunk)
File "/usr/lib/python3.8/ssl.py", line 1226, in recv
return self.read(buflen)
File "/usr/lib/python3.8/ssl.py", line 1101, in read
return self._sslobj.read(len)
OSError: [Errno 0] Error

环境细节:

Python版本:Python 3.8.5

guncorn 模块版本:20.0.4

gunicorn 配置文件:

"""Gunicorn configurations."""
import os

bind = "0.0.0.0:443"
workers = os.cpu_count() - 1
keyfile = "/home/xyz/certs/psa_xyz.key"
certfile = "/home/xyz/certs/psa_xyz.crt"
timeout = 120

标签: python-3.xflaskgunicorn

解决方案


另一个应用程序已经在使用该端口,或者您有防火墙问题阻止您访问该端口。要确认这一点,您可以尝试将端口更改为 5000。

所以你的配置应该看起来像这样。

"""Gunicorn configurations."""
import os

bind = "0.0.0.0:5000"
workers = os.cpu_count() - 1
keyfile = "/home/xyz/certs/psa_xyz.key"
certfile = "/home/xyz/certs/psa_xyz.crt"
timeout = 120

推荐阅读