-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
"ClientPayloadError: Response payload is not completed" with https://www.тв-програма.bg #3904
Comments
aiohttp does not support HTTP/2.0 |
This definitely could use some help with improving the UX. |
I have the same error, and I don't use HTTP/2 |
Python 3.7.3 Works OK (without pytest though) |
Looks like everything is OK at HTTP level |
But does it go ahead and upgrade to HTTP/2.0 as instructed? |
@innocencex logs or didn't happen |
@webknjaz It should be https://en.wikipedia.org/wiki/HTTP/1.1_Upgrade_header But The server should not respond with Anyway, server closes connection after sending a full reply. (Which also breaks rules, since HTTP/1.1 connections are keep-alive by default unless |
It seems we face broken reverse-proxy. Possibly upstream is HTTP/2, and reverse proxy pushes these headers to clients. I do not remember what should RFC-compliant client should do in that case. |
I'm facing the same issue in my company. Our app download large image files on AWS S3 buckets (HTTP 1) with aiohttp. It seems that when I overload the app with Locust, if I stop the Locust connections, the app raises this Exception. |
Looks like a different issue / cause. Please create a new issue with more details (traceback etc). |
This seems to resolve an issue with a feed that also sent HTTP2 Upgrade headers (possibly incorrectly) aio-libs/aiohttp#3904
I've also encountered this. httpstatusgoats.net is apparently PHP, but it looks like there's a common factor of Apache here... % curl -I https://httpstatusgoats.net/img/200.jpg
HTTP/2 200
date: Wed, 08 Apr 2020 15:16:20 GMT
server: Apache/2
last-modified: Sun, 30 Oct 2016 16:12:55 GMT
etag: "117d2-540175d29cfc0"
accept-ranges: bytes
content-length: 71634
content-type: image/jpeg
% http HEAD https://httpstatusgoats.net/img/200.jpg
HTTP/1.1 200 OK
accept-ranges: bytes
connection: Upgrade
content-length: 71634
content-type: image/jpeg
date: Wed, 08 Apr 2020 15:17:31 GMT
etag: "117d2-540175d29cfc0"
last-modified: Sun, 30 Oct 2016 16:12:55 GMT
server: Apache/2
upgrade: h2,h2c
|
@auscompgeek i have same bug with Apache & http2 |
Interestingly, I wasn't able to reproduce this issue locally. Eventually I discovered that I had aiohttp without the Cython extensions on my server (as I'm running Python 3.8 so pip grabbed the pure-Python wheel from PyPI), however I have aiohttp installed from the Arch Linux repos on my laptop (which does have the Cython extensions). After reinstalling aiohttp with the Cython extensions, I'm no longer able to reproduce this issue with httpstatusgoats.net. |
Oh, so the issue is only with the pure Python implementation. Can anybody confirm this with their cases? |
This seems to go away when I downgrade to 3.6.1 from 3.6.2 Update: I had this problem again, googled it and found myself :) I have now re-verified this with python 3.8.0 and 3.8.3 on mac. The problem is not present in 3.6.1 but appears in 3.6.2 It's not entirely clear; there might be some python version component here too. This fails with 3.6.1 on 3.8.0 on linux, but works with 3.6.1 on 3.8.5 on linux. |
I ran into this error on Python 3.8.2 in a docker image using the The error is also absent when I use 3.7.3 natively on my Mac. I originally encountered this with |
Under the assumption that my hypothesis is correct, this is not surprising, as there are wheels available for CPython 3.7 for both Linux and macOS.
This is useful. This server is providing a more specific Server header, so maybe someone else will be able to reproduce this with a local Apache. % http -v HEAD https://spacejam.com HEAD / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: spacejam.com
User-Agent: HTTPie/2.1.0
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: Upgrade, Keep-Alive
Content-Encoding: gzip
Content-Length: 2136
Content-Type: text/html; charset=UTF-8
Date: Fri, 08 May 2020 12:13:27 GMT
ETag: "1f01-5a4034fb45953-gzip"
Keep-Alive: timeout=5, max=100
Last-Modified: Fri, 24 Apr 2020 06:16:52 GMT
Server: Apache/2.4.41 () OpenSSL/1.0.2k-fips
Strict-Transport-Security: max-age=15768000
Upgrade: h2,h2c
Vary: Accept-Encoding |
Adding these request headers seems to solve the http2 issue.
But apparently there are other reasons causing "Response payload is not completed" error, which happens occasionally and hard to reproduce. |
I had the same issue with a server that responds with "Connection: Upgrade". Requests library could fetch the page without problems, and the main difference was, that requests sends "Connection: keep-alive" header and that makes the server respond with "Connection: Upgrade, keep-alive". So I used |
This is suggested in this aiohttp issue: aio-libs/aiohttp#3904
and try to upgrade our connection. By adding the keep-alive header this seems to solve the issue. aio-libs/aiohttp#3904 (comment)
I am using Python 3.7 on Google Cloud Function and tried all the suggested options in this thread to get rid of "aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed" error.
I think this issue is not yet resolved, can someone please explain the root cause and any possible workaround of this problem. P.S. - this behaviour is intermittent. Sometimes it passed, sometimes it got failed. Update: Below is the response header.
|
Note: the Response payload is not completed error can also happen, if the connection got unexpectedly interrupted for some reason. That includes unstable connections, or server side measures against (potentially unintended) DOS attacks or automation (e.g. bots) that might be in place. If it only happens from time to time, it sounds more like it's actually one of those situations, rather than the specific issue with the unwanted protocol Upgrade that was talked about here. You can try to inspect the Edit: nvm. It's possible that the |
I'm running into My attempted debugging of this issue is really similar to what @DusanMadar saw in #2954 (comment), except that the exception that causes the ClientPayloadError that's caught at aiohttp/aiohttp/client_proto.py Line 83 in 5d1a75e
Also cc @luvvien, you mention you found a solution in #2954 (comment), but that link is dead (and wayback machine hasn't scraped it). Any chance you remember? :-) |
My issue was from a proxy in between the client and the server that was disconnecting the connection when there's no packet received for longer than 5 minutes. curl was working fine because curl was sending keep-alive TCP probes while waiting for the data. aiohttp client doesn't do this, so it gets disconnected. Here is what I did to fix (python3.8.0, aiohttp==3.7.3) - from aiohttp import ClientSession, TCPConnector
from aiohttp.client_reqrep import ClientRequest
import asyncio
import socket
class KeepAliveClientRequest(ClientRequest):
async def send(self, conn: "Connection") -> "ClientResponse":
sock = conn.protocol.transport.get_extra_info("socket")
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 2)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)
return (await super().send(conn))
with ClientSession(request_class=KeepAliveClientRequest) as session:
response = await session.post(
url
headers={'Connection': 'keep-alive'}
) |
@iameugenejo your solution works for me! Thanks |
For more info, aio-libs/aiohttp#3904 It is not possible to fix it by bumping aiohttp since it is pinned by another dependency.
For more info, aio-libs/aiohttp#3904 It is not possible to fix it by bumping aiohttp since it is pinned by another dependency.
Hey everyone, I just released v3.9.4rc0. It'll hopefully help us get more complete tracebacks and that in turn, will let us know the underlying causes for this exception being raised — there may be several distinct behaviors underneath and we need to discover what they are. If you have ability to do so, please try out this pre-release in environments where you can reproduce your problems and come back with the logs with complete tracebacks. Let's figure this out together! |
Results in:
URL: https://www.тв-програма.bg
It works fine using a browser or curl.
There are not response headers related to content length:
Using aiohttp master (95ead73).
The text was updated successfully, but these errors were encountered: