I am using Python 3 to access twitter APi for some tweet analysis. However, i am not able to get any data through API call.

I already did tried upgrading requests and pyopensssl. But still issue persists

Here is the code

from tweepy import streaming
from tweepy import StreamListener
from tweepy import OAuthHandler
import time

ACCESS_TOKEN = 'XXX'
ACCESS_SECRET = 'XXX'
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'

class listener (StreamListener):

    def on_data(self, data):
        try:
            print(data)
            savefile = open('pythontweet.csv', 'a')
            savefile.write(data)
            savefile.write("\n")
            savefile.close()
        except Exception as e:
            print(f"Failed on {e}")
            time.sleep(10)

        return True

    def on_error(self, status):
        print(status)

auth = OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN,ACCESS_SECRET)
twitterStream = streaming.Stream(auth, listener())
twitterStream.filter(track=["python"])

I am getting the below error:

SSLError: HTTPSConnectionPool(host='stream.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/filter.json?delimited=length (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

However I should get stream of tweet in pythontweet.csv file

1 Answers

0
Nsikan Sylvester On

adding verify = False to twitterStream = streaming.Stream(auth, listener()) reference TWEEPY SSLerror regarding certificate

twitterStream = streaming.Stream(auth, listener(), verify = False)