@daxak

Как исправить ошибку asyncio — Unclosed connection?

fuzzer.py
import aiohttp
import asyncio


async def get_page(url=None, extensions=None):
    with open("wordlist.txt") as file:
        directories = file.readlines()
    data = []
    async with aiohttp.ClientSession() as session:
        for directory in directories:
            response = await session.get(url=f"{url}/{directory}")
            data.append([f"{url}/{directory}", response.status, response.content_length])
            for extension in extensions:
                response = await session.get(url=f"{url}/{directory}.{extension}")
                data.append([f"{url}/{directory}.{extension}", response.status, response.content_length])
    return data


async def main():
    await get_page()


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

main.py
from fuzzer import get_page
@dp.message_handler()
async def fuzzer(message: types.Message, state: FSMContext):
    await state.update_data(ex=message.text.split(','))
    data = await state.get_data()
    fuzz_data = await get_page(url=data['url'], extensions=data['ex'])
    cur_time = datetime.datetime.now().strftime('%d_%m_%Y_%H_%M')
    async with aiofiles.open(f"{data['url'][8:]}_{cur_time}.csv", 'w') as file:
        writer = AsyncWriter(file)
        await writer.writerow(
            [
                'URL',
                'Код статуса',
                'Длина контента'
            ]
        )
        await writer.writerows(
            fuzz_data
        )

    await state.finish()

2022-07-18 04:11:47,729 - ERROR - asyncio - Unclosed connection
client_connection: Connection<ConnectionKey(host='google.com', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
  • Вопрос задан
  • 314 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы