Traceback (most recent call last):
File "ldbotaio.py", line 126, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "ldbotaio.py", line 110, in main
await f1
File "ldbotaio.py", line 86, in botrun
port=WEBAPP_PORT,
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 107, in start_webhook
route_name=route_name)
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 78, in set_webhook
executor.set_webhook(webhook_path, route_name=route_name, web_app=web_app)
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 289, in set_webhook
self.loop.run_until_complete(self._startup_webhook())
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 526, in run_forever
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.7/logging/handlers.py", line 70, in emit
logging.FileHandler.emit(self, record)
File "/usr/local/lib/python3.7/logging/__init__.py", line 1131, in emit
self.stream = self._open()
File "/usr/local/lib/python3.7/logging/__init__.py", line 1121, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
NameError: name 'open' is not defined
Call stack:
File "/home/bot/ldbot/lib/python3.7/site-packages/aiohttp/client.py", line 347, in __del__
self._loop.call_exception_handler(context)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1634, in call_exception_handler
self.default_exception_handler(context)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1608, in default_exception_handler
logger.error('\n'.join(log_lines), exc_info=exc_info)
Message: 'Unclosed client session\nclient_session: <aiohttp.client.ClientSession object at 0x2b66aee70b00>'
Arguments: ()
import redis
import asyncio
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils.executor import start_webhook
from aiogram.contrib.middlewares.logging import LoggingMiddleware
import config as cfg
bot = Bot(token=cfg.bot_token)
dp = Dispatcher(bot)
dp.middleware.setup(LoggingMiddleware())
WEBHOOK_HOST = cfg.WEBHOOK_HOST
WEBHOOK_PATH = cfg.WEBHOOK_PATH
WEBHOOK_URL = f'{WEBHOOK_HOST}{WEBHOOK_PATH}'
WEBAPP_HOST = cfg.WEBAPP_HOST
WEBAPP_PORT = cfg.WEBAPP_PORT
async def on_startup(dispatcher: Dispatcher):
await bot.set_webhook(WEBHOOK_URL, drop_pending_updates=True)
async def on_shutdown(dispatcher: Dispatcher):
await bot.delete_webhook()
@dp.message_handler()
async def echo(message: types.Message):
await message.answer(message.text)
async def botrun():
start_webhook(
dispatcher=dp,
webhook_path=WEBHOOK_PATH,
skip_updates=True,
on_startup=on_startup,
on_shutdown=on_shutdown,
host=WEBAPP_HOST,
port=WEBAPP_PORT,
)
async def redisrun():
r = redis.Redis(host='localhost', port=6379, db=0)
p = r.pubsub()
p.subscribe('test')
while True:
mes = p.get_message()
if mes:
print(mes['data'])
await asyncio.sleep(0.5)
async def main():
f1 = asyncio.create_task(botrun())
f2 = asyncio.create_task(redisrun())
await f1
await f2
if __name__ == '__main__':
asyncio.run(main())
(bot) xxx@xxx:/home/bot/ldbot# python ldbotaio.py
1
Traceback (most recent call last):
File "ldbotaio.py", line 60, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "ldbotaio.py", line 56, in main
await f1
File "ldbotaio.py", line 38, in botrun
port=WEBAPP_PORT,
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 107, in start_webhook
route_name=route_name)
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 78, in set_webhook
executor.set_webhook(webhook_path, route_name=route_name, web_app=web_app)
File "/home/bot/ldbot/lib/python3.7/site-packages/aiogram/utils/executor.py", line 289, in set_webhook
self.loop.run_until_complete(self._startup_webhook())
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 526, in run_forever
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x2aaf3f3c3a58>
@dp.message_handler(content_types=['text', 'photo', 'video', 'document'])
async def send_msg(message:types.Message):
await bot.send_message(message.chat.id, "Этот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
datetime.datetime.now()
datetime.datetime.now() + datetime.timedelta(seconds=600)
await message.bot.restrict_chat_member(message.chat.id, message.reply_to_message.from_user.id, datetime.datetime.now() + datetime.timedelta(seconds=600))
import datetime
если еще не сделано.