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

Consider removing assert about HTTP Reason-Phrase being always present #3906

WouldYouKindly opened this issue Jul 15, 2019 · 3 comments · Fixed by #3909


Copy link

commented Jul 15, 2019


aiohttp has the following code:

def raise_for_status(self) -> None:
    if 400 <= self.status:
        assert self.reason  # always not None for started response
        raise ClientResponseError(

This assertion fails if the server omits Reason-Phrase, i.e. if response looks like HTTP/1.1 404 (no Not Found).

HTTP spec is not clear about whether reason must be provided, but e.g. this answer suggests that it may not be:

Maybe aiohttp should be more permissive in this case. For me, the problem is that hoverfly drops the reason phrase, which leads to aiohttp raising AssertionError. Reason can be set to an empty string if it is not found in response.


This comment has been minimized.

Copy link

commented Jul 16, 2019

That's interesting.
I expected that http parsers (both cython and pure python versions) set reason to empty string if omitted.
If it is not -- the PR for parsers fix is welcome.


This comment has been minimized.

Copy link

commented Jul 16, 2019

I find some website response without reason-phrase. I checked response.reason is None, is empty string OK? (assert "" still fail)

import aiohttp
import asyncio

url = ''

async def main():
    async with aiohttp.ClientSession() as client:
        async with client.get(url) as resp:

loop = asyncio.get_event_loop()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kk/.pyenv/versions/3.6.5/lib/python3.6/asyncio/", line 468, in run_until_complete
    return future.result()
  File "<stdin>", line 5, in main
  File "/Users/kk/.pyenv/versions/rssant/lib/python3.6/site-packages/aiohttp/", line 935, in raise_for_status
    assert self.reason  # always not None for started response

This comment has been minimized.

Copy link

commented Jul 25, 2019

I just encountered this issue while doing integration with one of my customer site.
Hoping to see the next release soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.