Ben*_*ang 10 python flask gunicorn
版本:Python 3.8.2 Flask 2.0.1 Werkzeug 2.0.1 Gunicorn 20.1.0
在python3.7或3.8中运行flask,gunicorn模式是'sync'或'gevent/eventlet',我在终端中得到相同的错误:“count必须是正整数(得到0)”,但浏览器中的网站似乎没有异常,chrome控制台也没有报错。
古尼康配置:
# gunicorn.conf.py
workers = 5
worker_class = "sync" # or "gevent"
bind = "0.0.0.0:8080"
Run Code Online (Sandbox Code Playgroud)
输出:
>>> gunicorn application:app -c ./gunicorn.conf.py
Starting gunicorn 20.1.0
Listening at: http://0.0.0.0:8080 (69063)
Using worker: sync # or "gevent"
Booting worker with pid: 69065
Booting worker with pid: 69066
Booting worker with pid: 69067
Booting worker with pid: 69068
Booting worker with pid: 69069
[69065] [ERROR] Error handling request
Traceback (most recent call last):
File "/Users/xxx/.virtualenvs/yyy/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 182, in handle_request
resp.write_file(respiter)
File "/Users/xxx/.virtualenvs/yyy/lib/python3.8/site-packages/gunicorn/http/wsgi.py", line 385, in write_file
if not self.sendfile(respiter):
File "/Users/xxx/.virtualenvs/yyy/lib/python3.8/site-packages/gunicorn/http/wsgi.py", line 375, in sendfile
self.sock.sendfile(respiter.filelike, count=nbytes)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/socket.py", line 482, in sendfile
return self._sendfile_use_sendfile(file, offset, count)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/socket.py", line 346, in _sendfile_use_sendfile
self._check_sendfile_params(file, offset, count)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/socket.py", line 460, in _check_sendfile_params
raise ValueError(
ValueError: count must be a positive integer (got 0)
Run Code Online (Sandbox Code Playgroud)
我因引用模板的 head 部分中的空 JavaScript 文件而收到错误。
<script src="static/js/main.js"></script>
Run Code Online (Sandbox Code Playgroud)
一旦我删除了引用,错误就消失了。我只是想区分,无论文件类型如何,对空文件的引用都会导致错误,并且它不仅仅与 url_for 函数相关。