Search code examples
pythonaiohttp

aiohttp - running client example "RuntimeError: SSL is not supported"


I'm just trying to go through the aiohttp examples but I get the error with the first one:

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://python.org')
        print(html)

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

Running this gets me this:

File "C:\ProgramData\Anaconda2\envs\asyncio\lib\site-packages\aiohttp\connector.py", line 887, in _get_ssl_context raise RuntimeError('SSL is not supported.') RuntimeError: SSL is not supported.

  • Python version: 3.7.3
  • aiohttp version: 3.5.4

I searched for the problem replicating but I couldn't find anything... which leads me to think there's something wrong with my setup. I'm running this on Windows 8.1 using Anaconda2 env.

What's going on?


Solution

  • Aiohttp imports ssl as follows:

    try:
        import ssl
        SSLContext = ssl.SSLContext
    except ImportError:  # pragma: no cover
        ssl = None  # type: ignore
        SSLContext = object # type: ignore
    

    If then it is still None, it rises error specified in your post. Thus, first of all try to import ssl manually. It should look somewhat like that:

    >>> import ssl
    >>> ssl
    <module 'ssl' from '/usr/lib/python3.6/ssl.py'>
    

    If it does not, then check/reinstall your python setup.