AttributeError: module 'tweepy' has no attribute 'Stream' #2146
-
QuestionI need help, tried googling and altering the code, still running to same error Relevant Codeimport tweepy
# from tweepy.streaming import Stream
import json
import csv
# import os
# from datetime import timedelta
from kafka import KafkaProducer
api_key = 'x'
api_secret = 'y'
access_token = 'z'
access_token_secret = '&'
kafka_bootstrap_server = 'localhost:9092'
kafka_topic = 'twitter_data'
csv_output = 'filepath/twitter-data-from-api.csv'
kafka_producer = KafkaProducer(bootstrap_servers=kafka_bootstrap_server)
class TweetStreamListener(tweepy.Stream):
def on_status(self, status):
try:
tweet_id = status.id
tweet_text = status.text
tweet_created = status.created_at.strftime('%Y-%m-%d %H:%M:%S')
tweet_data = {
'id': tweet_id,
'text': tweet_text,
'created at': tweet_created
}
kafka_producer.send(kafka_topic,
json.dumps(tweet_data).encode("UTF-8"),
api_version=(3, 5, 0))
with open(csv_output, 'a', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerows([[tweet_id, tweet_text, tweet_created]])
except Exception as e:
print(f"Error: {str(e)}")
def extract_data():
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
twitter_stream_listener = TweetStreamListener(api.auth, None)
stream = tweepy.Stream(auth=api.auth, listener=twitter_stream_listener)
stream.filter(['Key1', 'Key2', 'Key3'])
kafka_producer.close()
extract_data() TracebackTraceback (most recent call last):
File "filepath\twitter.py", line 21, in <module>
class TweetStreamListener(tweepy.Stream):
AttributeError: module 'tweepy' has no attribute 'Stream' Twitter API Access PlanFree Tweepy Version4.14.0 Checklist
Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
Harmon758
Jul 14, 2023
Replies: 1 comment
-
It's also not something that would have been available with Free access. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Harmon758
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tweepy.Stream
was removed in Tweepy v4.14.0, as streaming with Twitter API v1.1 has been deprecated.It's also not something that would have been available with Free access.
https://twittercommunity.com/t/announcing-new-access-tiers-for-the-twitter-api/188728
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api
https://developer.twitter.com/en