gpt4 book ai didi

python - 已达到速率限制。正在休眠 :

转载 作者:太空宇宙 更新时间:2023-11-03 21:20:08 26 4
gpt4 key购买 nike

我正在收集推文以及来自 Twitter 的 API 的回复来构建数据集,并且我正在 python 中使用 tweepy 库来实现这一点,但问题是我经常收到此错误(已达到速率限制。正在 sleep :(任何数字秒))会延迟我,我必须在最短的时间内收集尽可能多的数据

我读到 Twitter 的速率限制是每 15 分钟 15 个请求或类似的东西,但在我的情况下,我只能收集一条或两条推文,直到它再次停止,有时它会停止 15 分钟,然后再次停止15分钟,不给我时间,我不知道是什么导致了问题,是否是我的代码?

# Import the necessary package to process data in JSON format
try:
import json
except ImportError:
import simplejson as json

# Import the tweepy library
import tweepy
import sys

# Variables that contains the user credentials to access Twitter API
ACCESS_TOKEN = '-'
ACCESS_SECRET = '-'
CONSUMER_KEY = '-'
CONSUMER_SECRET = '-'

# Setup tweepy to authenticate with Twitter credentials:

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

# Create the api to connect to twitter with your creadentials
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, compression=True)



file2 = open('replies.csv','w', encoding='utf-8-sig')

replies=[]
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
for full_tweets in tweepy.Cursor(api.search,q='#عربي',timeout=999999,tweet_mode='extended').items():
if (not full_tweets.retweeted) and ('RT @' not in full_tweets.full_text):
for tweet in tweepy.Cursor(api.search,q='to:'+full_tweets.user.screen_name,result_type='recent',timeout=999999,tweet_mode='extended').items(1000):
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==full_tweets.id_str):
replies.append(tweet.full_text)
print(full_tweets._json)
file2.write("{ 'id' : "+ full_tweets.id_str + "," +"'Replies' : ")
for elements in replies:
file2.write(elements.strip('\n')+" , ")
file2.write("}\n")
replies.clear()



file2.close()

$ python code.py > file.csv

Rate limit reached. Sleeping for: 262 

Rate limit reached. Sleeping for: 853

最佳答案

希望这会有所帮助

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=False, compression=True)

关于python - 已达到速率限制。正在休眠 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54354516/

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