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
|
import asyncio
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
|
import structlog
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from .base import BaseSession, TemporaryError, Response
|
from .base import BaseSession, TemporaryError, Response
|
||||||
|
|
||||||
__all__ = ['session']
|
__all__ = ['session']
|
||||||
|
|
||||||
|
logger = structlog.get_logger(logger_name=__name__)
|
||||||
connector = aiohttp.TCPConnector(limit=20)
|
connector = aiohttp.TCPConnector(limit=20)
|
||||||
|
|
||||||
class AiohttpSession(BaseSession):
|
class AiohttpSession(BaseSession):
|
||||||
|
@ -31,12 +33,14 @@ class AiohttpSession(BaseSession):
|
||||||
) -> Response:
|
) -> Response:
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
|
'params': params,
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxy is not None:
|
if proxy is not None:
|
||||||
kwargs['proxy'] = proxy
|
kwargs['proxy'] = proxy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
logger.debug('send request', method=method, url=url, kwargs=kwargs)
|
||||||
res = await self.session.request(
|
res = await self.session.request(
|
||||||
method, url, **kwargs)
|
method, url, **kwargs)
|
||||||
except (
|
except (
|
||||||
|
@ -55,6 +59,6 @@ class AiohttpSession(BaseSession):
|
||||||
@atexit.register
|
@atexit.register
|
||||||
def cleanup():
|
def cleanup():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(session.close())
|
loop.run_until_complete(session.session.close())
|
||||||
|
|
||||||
session = AiohttpSession()
|
session = AiohttpSession()
|
||||||
|
|
Loading…
Add table
Reference in a new issue