Benji Wang
Benji Wang

Reputation: 187

run Flask with Gunicorn got "Error handling request [count must be a positive integer (got 0)]"

Versions: Python 3.8.2 Flask 2.0.1 Werkzeug 2.0.1 Gunicorn 20.1.0

Run flask in python3.7 or 3.8, and gunicorn mode is 'sync' or 'gevent/eventlet', I got the same error in terminal: "count must be a positive integer (got 0)", but the website in browser seems no abnormality, and the chrome console doesn't report error.

Gunicorn config:

# gunicorn.conf.py
workers = 5
worker_class = "sync"  # or "gevent"
bind = "0.0.0.0:8080"

Output:

>>> 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)

Upvotes: 10

Views: 5487

Answers (2)

LogDog23
LogDog23

Reputation: 316

I got the error from a reference to an empty JavaScript file in the head section of my template.

<script src="static/js/main.js"></script>

Once I removed the reference the error went away. I just wanted to make the distinction that a reference to an empty file causes the error regardless of filetype and that it isn't just related to the url_for function.

Upvotes: 9

Benji Wang
Benji Wang

Reputation: 187

I used the url_for function in template to reference an empty css file, that caused the exception.

Upvotes: 6

Related Questions