[Python] Please tell me how to disable SSL for aiohttpSession?

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing a small python 3.12 bot using aiogram3 and asyncio.

    The bot will be running at work, on one of the servers. There is a security policy that allows access to the external Internet only through a corporate proxy, so I also had to use aiohttp.

    I ran into a problem, I get an SSL validation error, because the http proxy is working, possibly for another reason. So, I'm asking for help - I've tried literally 10-15 Google search pages, neural networks, and the documentation of the libraries used, but I still haven't found a way to disable ssl verification.

    Code:

    import aiohttp
    import asyncio
    import logging
    from aiogram import Bot, Dispatcher, types
    from aiogram.filters.command import Command
    from aiohttp import BasicAuth
    from aiogram.client.session.aiohttp import AiohttpSession

    auth = BasicAuth(login='Login', password='Pass')
    session = AiohttpSession(proxy=('http://proxy.corp.company.ru:8080', auth))

    logging.basicConfig(level=logging.INFO)
    bot = Bot(token="token", session=session)
    dp = Dispatcher()

    @dp.message(Command("start"))
    async def cmd_start(message: types.Message):
    await message.answer("Hello!")

    async def main():
    await dp.start_polling(bot)

    if __name__ == "__main__":
    asyncio.run(main())


    Error: https://i.sstatic.net/825vbdvT.jpg

    What I've already tried:

    1). Use the TCPConnector(ssl = False)

    2). Run the script through a bat-file, enabling/disabling the proxy in it

    3). Create ssl_context, disable it, etc. (maybe it work, but i can't use context in session)

    Continue reading...

Compartilhe esta Página