How to use the nvchecker.source.aiohttp_httpclient.BetterClientSession function in nvchecker

To help you get started, we’ve selected a few nvchecker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lilydjwg / nvchecker / nvchecker / source / aiohttp_httpclient.py View on Github external
self.response = response

class BetterClientSession(aiohttp.ClientSession):
    async def _request(self, *args, **kwargs):
        if hasattr(self, "nv_config") and self.nv_config.get("proxy"):
            kwargs.setdefault("proxy", self.nv_config.get("proxy"))

        kwargs.setdefault("headers", {}).setdefault('User-Agent', DEFAULT_USER_AGENT)

        res = await super(BetterClientSession, self)._request(
            *args, **kwargs)
        if res.status >= 400:
            raise HTTPError(res.status, res.reason, res)
        return res

session = BetterClientSession(
    connector = connector,
    timeout = aiohttp.ClientTimeout(total=20),
    trust_env = True,
)

@atexit.register
def cleanup():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(session.close())

NetworkErrors = (
    asyncio.TimeoutError,
    aiohttp.ClientConnectorError,
)
github lilydjwg / nvchecker / nvchecker / source / aiohttp_httpclient.py View on Github external
async def _request(self, *args, **kwargs):
        if hasattr(self, "nv_config") and self.nv_config.get("proxy"):
            kwargs.setdefault("proxy", self.nv_config.get("proxy"))

        kwargs.setdefault("headers", {}).setdefault('User-Agent', DEFAULT_USER_AGENT)

        res = await super(BetterClientSession, self)._request(
            *args, **kwargs)
        if res.status >= 400:
            raise HTTPError(res.status, res.reason, res)
        return res