Answer the question
In order to leave comments, you need to log in
Aiogram how to fix Unclosed connector error?
Good day
I am writing a small bot that will send goods to the telegram channel at startup. That is, I do not need to maintain the session all the time, but only send a post (picture + text) to the cart 2-3 times a day.
Now the code looks like this.
from aiogram import Bot, types
import asyncio
API_TOKEN = '00000000000000000000000000'
CHANNEL_ID = -00000000000000000
bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.HTML)
async def send_good(chanel_id: int, text: str):
await bot.send_message(chanel_id, text)
async def start_post():
posted = False
while not posted:
await send_good(CHANNEL_ID, 'Some text')
posted = True
break
loop = asyncio.get_event_loop()
loop.run_until_complete(start_post())
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000026709284F10>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000002670928C340>, 18442.312)]']
connector: <aiohttp.connector.TCPConnector object at 0x0000026709284D90>
Answer the question
In order to leave comments, you need to log in
If anyone is interested, I rewrote the bot like this
import telebot
class TelegramPost:
TOKEN = settings.config['TOKEN']
GROUP_ID = settings.config['GROUP_ID']
bot = telebot.TeleBot(TOKEN, parse_mode='HTML')
def post_channel(self, image_url, caption):
photo = open(image_url, 'rb')
self.bot.send_photo(self.GROUP_ID, photo=photo, caption=caption)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question