gpt4 book ai didi

python - 使用 Tweepy 访问 twitter API 时出错

转载 作者:行者123 更新时间:2023-12-05 07:23:16 28 4
gpt4 key购买 nike

我正在使用 Python 3 访问 twitter APi 进行一些推文分析。但是,我无法通过 API 调用获取任何数据。

我已经尝试升级 requestspyopensssl。但问题依旧存在

这是代码

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"])

我收到以下错误:

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')])")))

但是我应该在 pythontweet.csv 文件中获取推文流

最佳答案

verify = False 添加到 twitterStream = streaming.Stream(auth, listener()) 引用 TWEEPY SSLerror regarding certificate

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

关于python - 使用 Tweepy 访问 twitter API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56090900/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com