gpt4 book ai didi

python - 属性错误: 'generator' object has no attribute 'connect' Pydle,异步

转载 作者:太空宇宙 更新时间:2023-11-03 15:14:08 24 4
gpt4 key购买 nike

尝试将 pydle 与 asyncio 一起使用。几个月前,我的代码运行得很好,现在我无法再运行它了。

@asyncio.coroutine
class MyOwnBot(pydle.Client):
async def on_connect(self):
await self.join('#new')

iclient = MyOwnBot('testeee', realname='tester')
loop = asyncio.get_event_loop()
asyncio.ensure_future(iclient.connect('irc.test.net', 6697, tls=True,tls_verify=False), loop=loop)

但我收到此错误:

asyncio.ensure_future(iclient.connect('irc.test.net', 6697, tls=True, tls_verify=False), loop=loop)
AttributeError: 'generator' object has no attribute 'connect'

最佳答案

pydletakes care of the event loop for you 。另外,将整个类标记为协程是行不通的;类不是工作单元,类上的方法才是工作单元。

为了确保跨 python 版本兼容性,该库包含它的 own async handling module :

import pydle

class MyOwnBot(pydle.Client):
@pydle.coroutine
def on_connect(self):
yield self.join('#new')

iclient = MyOwnBot('testeee', realname='tester')
iclient.connect('irc.test.net', 6697, tls=True, tls_verify=False)

Client.connect() 方法启动循环(但如果您需要在其他地方使用相同的循环,则可以传入一个循环)。

关于python - 属性错误: 'generator' object has no attribute 'connect' Pydle,异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44007989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com