AttributeError: 'generator' object has no attribute 'connect' Pydle, Asyncio
AttributeError: 'generator' object has no attribute 'connect' Pydle, Asyncio
正在尝试将 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。此外,将整个 class 标记为协程也不起作用; class 不是工作单元,方法 on class 是。
为了确保跨 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()
方法启动循环(但如果您需要在其他地方使用相同的循环,您可以传入一个)。
正在尝试将 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。此外,将整个 class 标记为协程也不起作用; class 不是工作单元,方法 on class 是。
为了确保跨 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()
方法启动循环(但如果您需要在其他地方使用相同的循环,您可以传入一个)。