Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server; POST-request; BadStatusLine: 400; an endless stream of exception messages that have no impact on operation. #8442

Closed
1 task done
PieceOfGood opened this issue Jun 6, 2024 · 1 comment
Labels
bug needs-info Issue is lacking sufficient information and will be closed if not provided Stale

Comments

@PieceOfGood
Copy link

Describe the bug

I get the following output when receiving requests from Telegram through the installed Webhook:

Error handling request
Traceback (most recent call last):
  File "G:\pyProj\lena-site\venv\Lib\site-packages\aiohttp\web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp\\_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:

    b'":27,"length":5,"type":"bold"}]},"text":"\\u041f\\u044f\\u0442\\u044c."}}POST /telegram/hook HTTP/1.1'
      ^
Error handling request
Traceback (most recent call last):
  File "G:\pyProj\lena-site\venv\Lib\site-packages\aiohttp\web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp\\_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:

    b't":"CHAT_MESSAGE:\\n\\u041f\\u043e\\u043b\\u044c\\u0437\\u043e\\u0432\\u0430\\u0442\\u0435\\u043b\\u044c Dobry \\u043d\\u0430\\u043f\\u0438\\u0441\\u0430\\u043b \\u0432 \\u0447\\u0430\\u0442:\\n\\n\\u0414\\u0430 \\u0431\\u0443\\u0434\\u0435\\u0442 \\u043f\\u044f\\u0442\\u044c.","entities":[{"offset":0,"length":13,"type":"underline"},{"offset":27,"length":5,"type":"bold"}]},"text":"\\u041f\\u044f\\u0442\\u044c."}}POST /telegram/hook HTTP/1.1'
      ^
...

Tests show that each such output contains a reaction to part of the line from the previous message (that is, received by the handler in the previous request), which, in principle, does not affect the operation of the script in any way. At the same time, sending the same text does not guarantee receiving a message about this error, which is why it is not possible to identify the pattern that influences the occurrence of this situation.

The method(read() | text() | json()) by which the contents of the request are received has no effect on this situation.

To Reproduce

An ordinary POST request handler that reads the content:

@routes.post("/telegram/hook")
@aiohttp_csrf.csrf_exempt
async def telegram_hook(request: Request) -> Response:
    """ Receives data from Telegram, processes it
    and sends a response.
    """

    secret_header = request.headers.get("X-Telegram-Bot-Api-Secret-Token", None)
    if secret_header != TG_SECRET_TOKEN:
        log.debug(
            "An incorrect secret was received in a message from Telegram:"
            f"\n{secret_header!r}"
        )
        return Response(status=404)

    body: bytes = await request.read()
    ...

Expected behavior

Since this exception does not affect the operation of the program in any way, I would like not to see messages about it. I haven't found a way to disable output for this particular situation.

Logs/tracebacks

The contents of the log are described above.

Python Version

$ python --version
Python 3.12.3

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.9.5
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: G:\pyProj\lena-site\venv\Lib\site-packages
Requires: aiosignal, attrs, frozenlist, multidict, yarl
Required-by: aiohttp-csrf, aiohttp-jinja2, aiohttp-security, aiohttp-session

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.5
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: G:\pyProj\lena-site\venv\Lib\site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.9.4
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Location: G:\pyProj\lena-site\venv\Lib\site-packages
Requires: idna, multidict
Required-by: aiohttp

OS

Windows 10 x64

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@PieceOfGood PieceOfGood added the bug label Jun 6, 2024
@Dreamsorcerer
Copy link
Member

Is this still occurring in 3.10.5? We fixed several parser issues that might have been the cause of these errors.

@Dreamsorcerer Dreamsorcerer added the needs-info Issue is lacking sufficient information and will be closed if not provided label Sep 7, 2024
@github-actions github-actions bot added the Stale label Oct 8, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-info Issue is lacking sufficient information and will be closed if not provided Stale
Projects
None yet
Development

No branches or pull requests

2 participants