1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1638 from coder2020official/master

Fixes #1637, #1636
This commit is contained in:
Badiboy 2022-07-18 18:14:52 +03:00 committed by GitHub
commit e553f3aa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
import asyncio # for future uses
import ssl
import aiohttp
import certifi
from telebot import types
try:
@ -26,18 +28,22 @@ REQUEST_LIMIT = 50
class SessionManager:
def __init__(self) -> None:
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(
limit=REQUEST_LIMIT
))
self.session = None
self.ssl_context = ssl.create_default_context(cafile=certifi.where())
async def create_session(self):
self.session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(
limit=REQUEST_LIMIT
limit=REQUEST_LIMIT,
ssl_context=self.ssl_context
))
return self.session
async def get_session(self):
if self.session is None:
self.session = await self.create_session()
return self.session
if self.session.closed:
self.session = await self.create_session()