尝试将 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'
最佳答案
pydle
库 takes 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/