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

ClientPayloadError with blank Content-Encoding header #1931

Closed
ikhlestov opened this issue May 29, 2017 · 3 comments
Closed

ClientPayloadError with blank Content-Encoding header #1931

ikhlestov opened this issue May 29, 2017 · 3 comments
Labels

Comments

@ikhlestov
Copy link

In case response contains blank Content-Encoding header call to await resp.text() will cause an error:

aiohttp.client_exceptions.ClientPayloadError: 400, message='Can not decode content-encoding: '

To reproduce you may use this two scripts - server:

from aiohttp import web
from multidict import MultiDict


async def index(request):
    return web.Response(
        text='Hello Aiohttp!',
        headers=MultiDict({'CONTENT-ENCODING': ''}))

app = web.Application()
app.router.add_get('/', index)
web.run_app(app, host='127.0.0.1', port=8080)

and client:

import asyncio

import aiohttp


async def fetch_page():
    async with aiohttp.ClientSession() as session:
        async with session.get('http://127.0.0.1:8080/') as resp:
            for key, value in resp.headers.items():
                print("%s:" % key, value)
            print(resp.status)
            # Failed on this call
            print(await resp.text())


loop = asyncio.get_event_loop()
loop.run_until_complete(fetch_page())

I don't know exactly why such thing happen, but I'd like to note that on versions of aiohttp prior 2.0 there is no such behavior. Other clients - wget/flask work without any errors.
And also seems that issue #1918 can have the same origin, but there Content-Encoding was provided as deflate.

Env:
Python 3.6.1
aiohttp==2.1.0
async-timeout==1.2.1
chardet==3.0.3
multidict==2.1.6
yarl==0.10.2

@asvetlov
Copy link
Member

It's bad HTTP servers I sure.
But aiohttp client should support them.
@ikhlestov please make a fix, it should be easy enough.

@fafhrd91
Copy link
Member

fixed in master

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants