python - Tweepy 没有返回给定数量的推文

标签 python python-3.x twitter tweepy twitterapi-python

我有以下代码

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 分钟可以拉取的推文的允许数量

检查 here获取更多信息。

关于python - Tweepy 没有返回给定数量的推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65351131/

相关文章:

python - 我如何使用 lxml 解析带有表单的结果页面?

python - Panda 的双括号索引 [[]]

推特数据文件

java - HTTPS 登录? java

android - 我可以作为开发人员测试我的应用程序而不被推特列入白名单吗

python - 这种对整数进行运算的 numpy 算法偶尔会返回 float ,为什么?

php - 在 PDF 中搜索并为其建立索引?

python - 查找第 n 个最常见的单词并在 python 中计数

python - 以 GitHub 为源的 CDK Codepipeline

python - 使用 urllib2 和 simplejson 无限循环