Search code examples
pythontweepy

Tweepy Stream Error "Stream encountered HTTP error: 403",


i have elevated access and turned on OAuth 1.0a, therefore i have access to the Twitter API v1.1. I try to stream specific keywords, however i always get the error "Stream encountered HTTP error: 403". Can anyone help?

import tweepy

apikey = "x"
apikeysecret = "x"
accesstoken = "x"
accesstokensecret = "x"
bearertoken = "x"

auth = tweepy.OAuth1UserHandler(apikey, apikeysecret, accesstoken, accesstokensecret)
api = tweepy.API(auth,wait_on_rate_limit=True)

class MyStreamListener(tweepy.Stream):
    def on_status(self, status):
        print(status.user.screen_name + ": " +status.text)

myStream = MyStreamListener(apikey,apikeysecret,accesstoken,accesstokensecret)
myStream.filter(track=["solana"])

Solution

  • Try adding auth.secure = True

    This is what your code would look like:

    import tweepy
    
    apikey = "x"
    apikeysecret = "x"
    accesstoken = "x"
    accesstokensecret = "x"
    bearertoken = "x"
    
    auth = tweepy.OAuth1UserHandler(apikey, apikeysecret, accesstoken, accesstokensecret)
    auth.secure = True
    api = tweepy.API(auth,wait_on_rate_limit=True)
    
    class MyStreamListener(tweepy.Stream):
        def on_status(self, status):
            print(status.user.screen_name + ": " +status.text)
    
    myStream = MyStreamListener(apikey,apikeysecret,accesstoken,accesstokensecret)
    myStream.filter(track=["solana"])