mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
fix aiohttp_httpclient
This commit is contained in:
parent
58a7ae05ca
commit
57626faecf
1 changed files with 5 additions and 1 deletions
|
@ -5,12 +5,14 @@ import atexit
|
|||
import asyncio
|
||||
from typing import Optional, Dict
|
||||
|
||||
import structlog
|
||||
import aiohttp
|
||||
|
||||
from .base import BaseSession, TemporaryError, Response
|
||||
|
||||
__all__ = ['session']
|
||||
|
||||
logger = structlog.get_logger(logger_name=__name__)
|
||||
connector = aiohttp.TCPConnector(limit=20)
|
||||
|
||||
class AiohttpSession(BaseSession):
|
||||
|
@ -31,12 +33,14 @@ class AiohttpSession(BaseSession):
|
|||
) -> Response:
|
||||
kwargs = {
|
||||
'headers': headers,
|
||||
'params': params,
|
||||
}
|
||||
|
||||
if proxy is not None:
|
||||
kwargs['proxy'] = proxy
|
||||
|
||||
try:
|
||||
logger.debug('send request', method=method, url=url, kwargs=kwargs)
|
||||
res = await self.session.request(
|
||||
method, url, **kwargs)
|
||||
except (
|
||||
|
@ -55,6 +59,6 @@ class AiohttpSession(BaseSession):
|
|||
@atexit.register
|
||||
def cleanup():
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(session.close())
|
||||
loop.run_until_complete(session.session.close())
|
||||
|
||||
session = AiohttpSession()
|
||||
|
|
Loading…
Add table
Reference in a new issue