aiohttp - running client example “RuntimeError: SSL is not supported”

穿精又带淫゛_ 提交于 2021-02-11 12:36:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/56629636/aiohttp-running-client-example-runtimeerror-ssl-is-not-supported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!