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

RuntimeError raised when a Redirect doesn't have a Location or URI HTTP header #2009

Closed
PCManticore opened this issue Jun 25, 2017 · 5 comments
Labels
Milestone

Comments

@PCManticore
Copy link
Contributor

Long story short

As per title, whenever a redirect response doesn't have a Location or a URI HTTP header, a RuntimeError will be raised by aiohttp. While this is indeed a problem, I think that raising RuntimeError seems a bit too much, since now I have to handle it explicitly in my code, rather than catching an aiohttp exception

Expected behaviour

For another exception, particular to aiohttp, to be raised, so that we can handle this case from our code, without hiding other bugs.

Actual behaviour

RuntimeError gets raised

Steps to reproduce

import aiohttp
import asyncio

async def fetch(session, url):
        async with session.get(url) as response:
            return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, 'http://www.droidreport.com/googles-market-android-wearables-7173')
        print(html)

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

Your environment

aiohttp==2.0.7
Python 3.6

@asvetlov
Copy link
Member

Well, a new class in http_exceptions.py derived from BadHttpMessage sounds like a good solution.

Would you make a PR?

@asvetlov asvetlov added this to the 2.3.0 milestone Jun 25, 2017
@PCManticore
Copy link
Contributor Author

Sure!

@asvetlov
Copy link
Member

Please note: procedure for adding changes to CHANGES.rst will be changed on #2010 merging.
I expect to finish the work in a few hours

PCManticore added a commit to PCManticore/aiohttp that referenced this issue Jun 25, 2017
Raise `RedirectWithoutLocationError` if a redirect response has
no Location or URI HTTP header.
Close aio-libs#2009
PCManticore added a commit to PCManticore/aiohttp that referenced this issue Jun 25, 2017
Raise `RedirectWithoutLocationError` if a redirect response has
no Location or URI HTTP header.
Close aio-libs#2009
PCManticore added a commit to PCManticore/aiohttp that referenced this issue Jun 25, 2017
Raise `RedirectWithoutLocationError` if a redirect response has
no Location or URI HTTP header.
Close aio-libs#2009
PCManticore added a commit to PCManticore/aiohttp that referenced this issue Jun 25, 2017
Raise `RedirectURLError` if a redirect response has
no Location or URI HTTP header.
Close aio-libs#2009
@asvetlov
Copy link
Member

asvetlov commented Jun 26, 2017

Sorry, I misleaded you. Proper exception class should derive from ClientResponseError.
Fixed by 9ff2e40

@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

2 participants