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
Bad status line 'Invalid method encountered' when sending a request with comperss=True #6566
Comments
i was able to reproduce the bug.Will raise fix in next 2-3 days. |
Hi, @thisisamardeep! Have you been able to make a fix for the bug? I've done some more research and it seems to me that the errors only happen when request method is GET or request body is empty (which makes sense cause there is nothing to actually compress). The workaround is pretty simple but the error is still pretty annoying :( |
Has this been fixed? |
Is it possible to handle this exception in middleware? |
I meet this problem, too. |
I got this a lot these days. |
Faced the same problem when I pass headers. |
It looks like a problem with the server rather than the client, for keepalive connections. The messages sent by the client seem correct. I wonder if it's related to the use of compression somehow. Here is an example Wireshark trace, ignore the extra headers in the last request, they're wrong but they're unrelated to this problem Wireshark follow TCP streamGET /mail/inbox/ HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-GB Accept-Encoding: gzip, deflate, br Content-Type: application/x-www-form-urlencoded Content-Length: 75 Origin: http://localhost:8080 DNT: 1 Connection: keep-alive Referer: http://localhost:8080/account/login/ Cookie: si="27X41k5NQBLQRbrHZMf/Sbut58bxNd622J8VDgDfZQnQkV8SehHEKaTpyvvCQe37G3aY9UK36+rz" Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: same-origin Sec-Fetch-User: ?1 X-Forwarded-for: 127.0.0.1 |
Facing the same issue after we enabled TLS 1.3 in the server. |
I'd check openssl version, I've no idea what the problem would be otherwise. If on a supported version, then it'd probably be a good idea to hack some aiohttp code and try and print out the raw data, to see what's coming through. |
Thanks @Dreamsorcerer I was able to capture the net packages and decrypt the TLS records, The http request was sent in two TLS records: one contains the http header part, the other contains the payload part, I can confirm the content of both header part and payload part are correct. From the error message, my wild guess is that the server didn't assembly them together and was trying to parse the payload part as a whole http request. While when using TLS 1.2, though the http request was also sent in the same way (header and payload contained in two TLS records), seems the server was able to assembly them together before parsing. header: payload: Error: |
I don't have time to look at anything yet, but if you could debug further and figure out exactly what's happening in the code, that'd be great. I'd start by printing |
Describe the bug
We were trying to use gzip compression in requests between python applications, both using aiohttp (aiohttp.ClientSession on client side, somewhat modded aiohttp.web.Application on server side). Setting
compress
parameter inaiohttp.ClientSession.request
toTrue
(or"gzip"
as we first tried) results in strange errors in the server app:The request was actually processed and client app got the correct response, but those errors still appear in server logs. Sometimes (not actually sure, when) requests fail with 400 Bad Request HTTP error. Adding HTTP header
{'Content-Encoding': 'gzip'}
doesn't fix the problem in any way.To Reproduce
Client prints
Hello, world
and resp.raise_for_status() didn't raise any errors.Server prints the following:
Expected behavior
The server is supposed to process the request and not give any errors.
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
macOS Monterey 12.1
Related component
Server, Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: