0
我想在Python和MongoDB之間設置一個連接來存儲推文。我的問題是,我在Mylistener
的每個請求中獲得401。你能幫我解決這個問題嗎?401錯誤python MongoDB連接
class MyListener(StreamListener):
def __init__(self, start_time, time_limit=60):
self.time = start_time
self.limit = time_limit
self.tweet_data = []
def on_data(self, data):
while (time.time() - self.time)<self.limit:
try:
client = MongoClient('localhost',27017)
client.server_info()
db = client.tweets_db
collection = db.collect_tweets
tweet = json.loads(data)
collect_tweets.insert(tweet)
return True
except BaseException as e:
print("Error on_data: %s" % str(e))
return True
def on_error(self, status):
print(status)
Keywords_list=['word1','word2','word3']
twitter_stream = Stream(auth, MyListener(start_time, time_limit))
401見here代表URL受密碼保護。 –