Sending 0 byte files now triggers an exception in 3.7.0 #5124
Closed
Description
🐞 Describe the bug
#4517 caused a regression with 0 byte files.
💡 To Reproduce
Send a 0 byte file with aiohttp.web.FileResponse on python 3.7 or later
💡 Expected behavior
No exception
📋 Logs/tracebacks
Traceback (most recent call last):
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 461, in start
resp, reset = await task
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 414, in _handle_request
reset = await self.finish_response(request, resp, start_time)
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 568, in finish_response
await prepare_meth(request)
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_fileresponse.py", line 373, in prepare
return await self._sendfile(request, fobj, offset, count)
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_fileresponse.py", line 191, in _sendfile_system
await writer.sendfile()
File "/__w/core/core/venv/lib/python3.7/site-packages/aiohttp/web_fileresponse.py", line 107, in sendfile
self._count
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1044, in sendfile
offset, count)
File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 551, in _sendfile_native
fallback=False)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 788, in sock_sendfile
self._check_sendfile_params(sock, file, offset, count)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 842, in _check_sendfile_params
"count must be a positive integer (got {!r})".format(count))
ValueError: count must be a positive integer (got 0)📋 Your version of the Python
$ python --version
Python 3.8.1
...📋 Your version of the aiohttp/yarl/multidict distributions
$ python -m pip show aiohttp
...$ python -m pip show multidict
...$ python -m pip show yarl
...📋 Additional context