I wanna sniffer https requests but failed with the sslError
I wanna let aiohttp session trust my charles root certificate(my os has trusted it already), or skip ssl verify.
Neigher does the aiohttp session trust chrales certificate, nor does it skip ssl verify
import asyncio
import aiohttp
async def sync(i):
url = 'https://baidu.com'
async with aiohttp.ClientSession() as session:
print('synci'+i)
data = {
'key': 'abc',
}
async with session.post(url, data=data,proxy="http://127.0.0.1:8888") as resp:
#assert await resp.json() == { "cookies": {"cookies_are": "working"}}
print(await resp.text())
async def f1(i):
print('init'+str(i));
await sync(str(i));
r1=f1(1)
r2=f1(2)
print('start')
asyncio.get_event_loop().run_until_complete(asyncio.gather(*[ r1, r2, ]))
Output:
ssl.SSLError: [SSL] shutdown while in init (_ssl.c:2098)
python3.5.2
mac osx
Unfortunately the issue is out of scope of aiohttp.
You could create aiohttp.Connector with custom ssl_context (see https://docs.python.org/3/library/ssl.html for how to create ssl context object).
Perhaps you have to configure the context properly using your cert chains.
P.S. aiohttp.Connector(verify_ssl) disables SSL certs verification.
@asvetlov
Unfortunately, _aiohttp's seesion_ does not support Connector: TypeError: _request() got an unexpected keyword argument 'connector'
import asyncio
import aiohttp
async def sync(i):
url = 'https://baidu.com'
async with aiohttp.ClientSession() as session:
print('synci'+i)
data = {
'key': 'abc',
}
help(session.post)
async with session.post(url, data=data,proxy="http://127.0.0.1:8888", connector=aiohttp.TCPConnector(verify_ssl=False)) as resp:
#assert await resp.json() == { "cookies": {"cookies_are": "working"}}
print(await resp.text())
async def f1(i):
print('init'+str(i));
await sync(str(i));
r1=f1(1)
r2=f1(2)
print('start')
asyncio.get_event_loop().run_until_complete(asyncio.gather(*[ r1, r2, ]))
Pass connector instance into aiohttp.ClientSession constructor, not into session.post() coroutine.
@asvetlov It works, many thanks!
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].
Most helpful comment
Unfortunately the issue is out of scope of aiohttp.
You could create
aiohttp.Connectorwith customssl_context(see https://docs.python.org/3/library/ssl.html for how to create ssl context object).Perhaps you have to configure the context properly using your cert chains.
P.S.
aiohttp.Connector(verify_ssl)disables SSL certs verification.