aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

BadStatusLine: 400 not expected random exceptions

Open iandresolares opened this issue 3 years ago • 1 comments

Describe the bug

Hi, I have setup a webserver which handles some POST requests. This works fine, however when the server is running for some hours I start to see some errors handling requests which were not supposed to happen: Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/aiohttp/web_protocol.py", line 314, in data_received messages, upgraded, tail = self._request_parser.feed_data(data) File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"

This happens a few times every few hours and I am the only one doing requests to the webserver right now so I have control of them. I have read some issues having similar problems but I still can't find a solution. What are these requests which fail? It doesn't make my system fail or anything but it is very annoying to try to find something in the logs and just see a bunch of these exceptions and I haven't been able to wrap it in a Try Except block. Where should I place this try except block if that would be the solution?

To Reproduce

  1. Set up a webserver:
app = web.Application()
app.add_routes([web.post("/whatever", handler)])

async def create_webserver():
    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner)
    await site.start()

await create_webserver()
  1. Run it.

Expected behavior

To not get BadStatusLine: 400 exception when there are no expected requests.

Logs/tracebacks

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/aiohttp/web_protocol.py", line 314, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"

Python Version

Version: 3.9.10

aiohttp Version

Version: 3.7.4

multidict Version

Version: 5.2.0

yarl Version

Version: 1.7.2

OS

Ubuntu 20.04

Related component

Server

Additional context

No response

Code of Conduct

  • [x] I agree to follow the aio-libs Code of Conduct

iandresolares avatar Apr 18 '22 13:04 iandresolares

This error happens whenever there is a request with a invalid HTTP verb. Any production server will receive many invalid requests and they shouldn't all throw errors. This buries real errors in the code. Such issues should be logged separately.

mousetail avatar May 10 '22 09:05 mousetail