解决pyhton aiohttp ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

解决pyhton aiohttp ssl:证书报错问题,

错误信息>

Cannot connect to host oapi.dingtalk.com:443 ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)]

解决方案就是取消ssl验证;

aiohttp.Connector使用自定义创建ssl_context有关如何创建ssl上下文对象,请参阅https://docs.python.org/3/library/ssl.html)。
也许您必须使用您的证书链正确配置上下文。

PS aiohttp.Connector(verify_ssl)禁用SSL证书验证。

在 ClientSession()传入ssl 配置

 1 import asyncio 
 2 import sys
 3 import pymysql.cursors
 4 from aiohttp import ClientSession
 5 from aiohttp import TCPConnector
 6 
 7 
 8 
 9 
10 
11 async def postmsg(url,msg):     
12     async with ClientSession(connector=TCPConnector(verify_ssl=False)) as session:                
13         # data={"msgtype":"text","text":{"content":msg},"at":{"atMobiles":["17633919216"],"isAtAll":"false"}}               
14         async with session.post(url,data=json.dumps(msg),headers=headers) as response:           
15             response = await response.read()                         
16             # print(response) 
17             return  response

猜你喜欢

转载自www.cnblogs.com/zhuyu/p/10249081.html
今日推荐