Skip to content

Value Error Could not parse hostname from URL 'http://' #2241

Closed
@steven2308

Description

Long story short

When a request response is a redirect but location has an invalid url, a ValueError is raised.

Expected behaviour

raise a ClientError or some more specific error.

Actual behaviour

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
    return future.result()
  File "/usr/lib/python3.6/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "<stdin>", line 4, in process
  File "/myenv/lib/python3.6/site-packages/aiohttp/client.py", line 604, in __aenter__
    self._resp = yield from self._coro
  File "/myenv/lib/python3.6/site-packages/aiohttp/client.py", line 228, in _request
    session=self, auto_decompress=self._auto_decompress)
  File "/myenv/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 97, in __init__
    self.update_host(url)
  File "/myenv/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 126, in update_host
    "Could not parse hostname from URL '{}'".format(url))
ValueError: Could not parse hostname from URL 'http://'

Steps to reproduce

import aiohttp

async def process():
    url = 'http://999pokers.info/'
    session = aiohttp.ClientSession()
    async with session.get(url) as response:
        print(response)
    session.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(
    process()
)
loop.close()

Your environment

Python 3.6.0b2
Ubuntu 16.10
aiohttp==2.2,5
Also happens with aiohttp==2.3.0a0 (installed from git on 04/Sep/2017)

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions