'Unauthorized: 401 Unauthorized 32 - Could not authenticate you

I am trying to get the data related to a specific hashtags from a specific location , but I am getting error.. I searched on the internet that it can be because of the since but I am not sure what to use instead of since in order not to get the error and my code work? any help or guidance appreciated!

import tweepy
import datetime

TWITTER_CONSUMER_KEY = '-'
TWITTER_CONSUMER_SECRET = '-'
TWITTER_ACCESS_TOKEN = '-'
TWITTER_ACCESS_TOKEN_SECRET = '-'

auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)


api = tweepy.API(auth,wait_on_rate_limit=True)

today = datetime.date.today()
yesterday= today - datetime.timedelta(days=1)
today, yesterday

tweets_list = tweepy.Cursor(api.search_tweets, q="#Covid-19 since:" + str(yesterday)+ " until:" + str(today),tweet_mode='extended', lang='it').items()


place = 'London'
tweets_list = tweepy.Cursor(api.search_tweets, q="place: " + place,tweet_mode='extended', lang='it').items()


output = []
for tweet in tweets_list:
    text = tweet._json["full_text"]
    print(text)
    favourite_count = tweet.favorite_count
    retweet_count = tweet.retweet_count
    created_at = tweet.created_at
    
    line = {'text' : text, 'favourite_count' : favourite_count, 'retweet_count' : retweet_count, 'created_at' : created_at}
    output.append(line)

The error:

Unauthorized: 401 Unauthorized
32 - Could not authenticate you.


Solution 1:[1]

So it seems that you don't have the right twitter permissions.

You have different leve of permissions that you can see here

You have to login, change your permissions and regenerate your api key to get it working

Good luck

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1