Session.get and throw an AssertionError when URL scheme is invalid

I’m developing a django app that comminucates with an API that we have also developed. I’m trying to neatly handle any possible errors, so I can log and display what’s going on. However when I write a URL with an invalid scheme I get an AssertionError back from aiohttp. Ideally I would prefer to avoid catching such rather generic errors if at all possible.

Is there a better way to catch this error?

async def aiohttp_call(num):
    async with aiohttp.ClientSession(raise_for_status=True) as session:
        url = f"ttps://{num}"
        async with session.get(url) as res:
            result = await res.json()
            return result["name"]



Traceback (most recent call last):
  File "", line 98, in <module>
  File "lib\site-packages\asgiref\", line 204, in __call__
    return call_result.result()
  File "C:\Users\uczmh2\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\", line 433, in result
    return self.__get_result()
  File "C:\Users\uczmh2\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\", line 389, in __get_result
    raise self._exception
  File "lib\site-packages\asgiref\", line 270, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "", line 94, in aiohttp_call
    async with session.get(url) as res:
  File "lib\site-packages\aiohttp\", line 1138, in __aenter__
    self._resp = await self._coro
  File "lib\site-packages\aiohttp\", line 535, in _request
    conn = await self._connector.connect(
  File "lib\site-packages\aiohttp\", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "lib\site-packages\aiohttp\", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "lib\site-packages\aiohttp\", line 1146, in _create_direct_connection
    assert port is not None