I'm trying to run AsyncStream Tweepy, but I ran into a problem
My code
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())
When I run it in .py file, it doesn't work and returns the error "An HTTP: 420 error occurred in the stream". I also run the code in Jupyter Notebook, only instead of async io.run(main ()), I write await main(), it also returns this error, BUT the stream works and it returns a response.
Why does it work in Jupyter Notebook, but does not work in the .py file. How can this be fixed?