使用 Tweepy AsyncStream 异步传输推文

问题描述

我正在尝试运行 AsyncStream Tweepy,但遇到了问题

我的代码

from __future__ import absolute_import,print_function
from tweepy.streaming import Stream
from tweepy import OAuthHandler
from tweepy import Stream
from pprint import pprint
from tweepy.asynchronous import AsyncStream 
import asyncio

async def main():

    stream = StdOutListener(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN,ACCESS_TOKEN_SECRET)
    await stream.filter(follow=['1082189695252074496'])
    await asyncio.sleep(1.5)


class StdOutListener(AsyncStream):
    
    
    async def on_status(self,status):
        print(status_json)

    async def on_error(self,status):
        print(status)
            
if __name__ == '__main__':
    asyncio.run(main())

当我在 .py 文件中运行它时,它不起作用并返回错误“An HTTP: 420 error occurred in the stream”。 我也在 Jupyter Notebook 中运行代码,只是我写了 await main() 而不是 async io.run(main()),它也返回此错误,但流工作并返回响应。

为什么它在 Jupyter Notebook 中有效,而在 .py 文件中无效。如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)