[英]Tweepy not returning the given amount of tweets
我有以下代碼
api = tweepy.API(auth,wait_on_rate_limit=True)
for tweet in tweepy.Cursor(api.search,
tweet_mode="extended",
q=query + " exclude:retweets").items(11000):
hashtags = "#" + " #".join([hashtag['text'] for hashtag in tweet.entities.get('hashtags')])
print(i)
if tweet.place:
tweet_place = tweet.place.full_name + ', ' + tweet.place.country_code
else:
tweet_place = "Not Geo-tagged"
i += 1
csvWriter.writerow([tweet.id, tweet.full_text.encode('utf-8'), tweet.created_at, tweet.lang, tweet.retweet_count, tweet.favorite_count, tweet_place, tweet.user.id, tweet.user.screen_name, tweet.user.followers_count, tweet.user.friends_count, tweet.user.created_at, tweet.user.favourites_count, tweet.user.statuses_count, tweet.user.lang, tweet.user.verified, tweet.user.location])
我正在嘗試使用特定的搜索查詢獲取 11000 條推文,但一段時間后它會引發以下錯誤:
Traceback (most recent call last):
.............
ConnectionResetError: [Errno 54] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
.............
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
.............
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
.............
tweepy.error.TweepError: Failed to send request: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
早些時候它發生在大約 2500 條推文中,但在更改查詢后,它開始在大約 5000 條推文中發生。 知道什么是錯的,我該如何解決?
這很可能是因為您超過了允許的推文數量,您可以一次/每 15 分鍾拉取
在這里查看更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.