I’m fairly new to coding, so I’m not quite sure what to do. I’m using a MacBook and downloaded PyCharm for my coding class, and so far, I’ve been able to figure most things out, but I’m stuck on this one.
I’m trying to get the tweepy Stream Listener to return the tweets for a certain hashtag, and this code worked without issue on the Windows computers on campus.
The code I’m running looks like this:
import tweepy #override tweepy.StreamListener to add logic to on_status class MyStreamListener(tweepy.StreamListener): def on_status(self, status): print(status.text) def on_error(self, status_code): if status_code == 420: # returning False in on_data disconnects the stream return False auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) myStreamListener = MyStreamListener() myStream = tweepy.Stream(auth, listener=myStreamListener) myStream.filter(track=['#fakenews'])
On my computer, it returns this error:
Traceback (most recent call last): File "/Users/USERNAME/PycharmProjects/Homework/Twitter.py", line 7, in import tweepy File "/Users/USERNAME/PycharmProjects/Homework/venv/lib/python3.7/site-packages/tweepy/init.py", line 17, in <module> from tweepy.streaming import Stream, StreamListener File "/Users/USERNAME/PycharmProjects/Homework/venv/lib/python3.7/site-packages/tweepy/streaming.py", line 358 def _start(self, async): ^ SyntaxError: invalid syntax
The last two “files” in the error are the code from the tweepy module, not any code I’ve written or searched through, and the error comes from one of those backend files.
I’ve tried changing the interpreter for my project in PyCharm, but I’m not sure what else to try. My professor looked at it and didn’t want to get into the backend code (and honestly, I don’t either, since I don’t really know what I’m doing), so I’m stuck as to what the real issue is.