English 中文(简体)
Aio http://www.ohchr.org
原标题:Aiohttp and Asyncio give an error when writing a bot on aiogram

I m 在Aiogram上写了一把机器人。 我根据文件做了一切,但我有了一个错误。 我第一次看到她。 请帮助我解决问题

def on_startup(bot: Bot) -> None:
    asyncio.create_task(start_schedule(bot))


async def start_schedule(botself):
    aioschedule.every().day.at( 00:00 ).do(lottery.lottery_finish, botself)
    while True:
        await aioschedule.run_pending()
        await asyncio.sleep(1)


async def main():
    bot = Bot(token=BOT_TOKEN, parse_mode= html )
    dp = Dispatcher()

    dp.startup.register(on_startup)

    dp.include_routers(main_menu.router, order.router, report.router, phone.router, location.router, receipt_scan.router, admin_panel.router, lottery_panel.router, products_panel.router, post_panel.router, markets_panel.router, early_close_panel.router, code.router, pre_admin_panel.router, availability_panel.router)
    await bot.delete_webhook(drop_pending_updates=True)
    await dp.start_polling(bot)


if __name__ ==  __main__ :
    logging.basicConfig(level=logging.INFO, stream=sys.stdout)
    asyncio.run(main())

error in text format:

Traceback (most recent call last):
  File "C:UsersDTEAAPycharmProjectschester_users2ot.py", line 44, in <module>
    asyncio.run(main())
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncio
unners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioase_events.py", line 642, in run_until_complete
    return future.result()
  File "C:UsersDTEAAPycharmProjectschester_users2ot.py", line 39, in main
    await dp.start_polling(bot)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libsite-packagesaiogramdispatcherdispatcher.py", line 526, in start_polling
    await self.emit_startup(bot=bots[-1], **workflow_data)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libsite-packagesaiogramdispatcher
outer.py", line 230, in emit_startup
    await self.startup.trigger(*args, **kwargs)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libsite-packagesaiogramdispatchereventevent.py", line 42, in trigger
    await handler.call(*args, **kwargs)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libsite-packagesaiogramdispatchereventhandler.py", line 48, in call
    return await loop.run_in_executor(None, wrapped)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libconcurrentfutures	hread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:UsersDTEAAPycharmProjectschester_users2ot.py", line 18, in on_startup
    asyncio.create_task(start_schedule(bot))
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncio	asks.py", line 360, in create_task
    loop = events.get_running_loop()
RuntimeError: no running event loop
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x00000224FFE334C0>
ERROR:asyncio:Unclosed connector
connections: [ [(<aiohttp.client_proto.ResponseHandler object at 0x00000224FFE133A0>, 6128.968)] ]
connector: <aiohttp.connector.TCPConnector object at 0x00000224FFE33340>
ERROR:asyncio:Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x00000224FFE33970>
transport: <_ProactorSocketTransport fd=596 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 684, in _process_write_backlog
    self._transport.write(chunk)
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 359, in write
    self._loop_writing(data=bytes(data))
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 395, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
AttributeError:  NoneType  object has no attribute  send 
sys:1: RuntimeWarning: coroutine  start_schedule  was never awaited
Exception ignored in: <function _SSLProtocolTransport.__del__ at 0x00000224EFC60D30>
Traceback (most recent call last):
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 321, in __del__
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 316, in close
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 593, in _start_shutdown
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 598, in _write_appdata
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 706, in _process_write_backlog
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasynciosslproto.py", line 720, in _fatal_error
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 151, in _force_close
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioase_events.py", line 746, in call_soon
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libasyncioase_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed

Process finished with exit code 1

StackOverflow asks for more characters because there is a lot of code in the question. don t pay attention to this text

问题回答
  File "C:UsersDTEAAAppDataLocalProgramsPythonPython39libsite-packagesaiogramdispatchereventhandler.py", line 48, in call
    return await loop.run_in_executor(None, wrapped)

这同你的问题一样。 图书馆正在铺设开机,这样,如果你试图开车,它就失败了。

这种做法似乎是一种坏的做法,即像一个yn图书馆为这种使用案件铺设了一条线。 我建议开一个问题,看看图书馆维护者的想法是什么,但如果他们希望启动任务,那么我会像你在这里那样,接受一个星号的功能,并使用<条码>。

同时,或许你可以找到一条途径,把 lo从主线上传来,并作为工作方使用<条码>。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签