Home:ALL Converter>Error 32 when Twitter sign in with Django AllAuth and post tweet with Tweepy

Error 32 when Twitter sign in with Django AllAuth and post tweet with Tweepy

Ask Time:2021-11-02T15:28:46         Author:Brenden

Json Formatter

I'm using Django AllAuth for twitter login, and it's working perfectly and saving the token and token secret to the Social Account Tokens table.

I'm then trying to use Tweepy to send a tweet on the user's behalf (yes, the scope allows that).

But when I try to send the tweet, I get tweepy.error.TweepError: [{'code': 32, 'message': 'Could not authenticate you.'}]

Here's the auth code:

def auth_tweepy(user):
    twitter_auth_keys = settings.TWITTER_AUTH_KEYS
    auth = tweepy.OAuthHandler(
        twitter_auth_keys['consumer_key'],
        twitter_auth_keys['consumer_secret']
    )
    user_auth = SocialToken.objects.get(account__user=user, account__provider='twitter')
    auth.set_access_token(
        user_auth.token,
        user_auth.token_secret
    )
    return tweepy.API(auth)

def send_tweet(tweet_content):
    api = auth_tweepy(user)

    try:
        api.update_status(tweet_content)
    except tweepy.TweepError as error:
        if error.api_code == 187:
            print('duplicate message')

I dont think the tokens are expired bc I JUST logged in. Any ideas what might cause the 32 error in this case?

Author:Brenden,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69806733/error-32-when-twitter-sign-in-with-django-allauth-and-post-tweet-with-tweepy
yy