Exemplo n.º 1
0
async def fetch(url: str):
    session = ClientSession()
    try:
        mozzila_root = get_mozzila_ca_crt()
        ssl_context = ssl_context_for_root(mozzila_root)
        response = await session.get(url, ssl=ssl_context)
        await session.close()
        return await response.text()
    except Exception as e:
        await session.close()
        log.error(f"Exception while fetching {url}, exception: {e}")
        return None
Exemplo n.º 2
0
async def fetch(url: str):
    async with ClientSession() as session:
        try:
            mozzila_root = get_mozzila_ca_crt()
            ssl_context = ssl_context_for_root(mozzila_root)
            response = await session.get(url, ssl=ssl_context)
            if not response.ok:
                log.warning("Response not OK.")
                return None
            return await response.text()
        except Exception as e:
            log.error(f"Exception while fetching {url}, exception: {e}")
            return None
Exemplo n.º 3
0
async def post(session: aiohttp.ClientSession, url: str, data: Any):
    mozzila_root = get_mozzila_ca_crt()
    ssl_context = ssl_context_for_root(mozzila_root)
    response = await session.post(url, json=data, ssl=ssl_context)
    return await response.json()