4

I have been using tweepy to track tweets through given periods of time (intervals within the past 7 days of my searches), although my issue now is that when searching and storing tweets based on a highly used query search (i.e. a trending topic) tweepy sends me back an error saying the connection timed out.

Here is my code:

results = []
for tweet in tweepy.Cursor(api.search, q="trump",count=100, result_type='recent',
                           include_entities=True, monitor_rate_limit=True, 
                           since="2016-05-12",until="2016-05-13", wait_on_rate_limit=True, timeout=999999).items():
    results.append(tweet)

and the error:

TweepError: Failed to send request: HTTPSConnectionPool(host='api.twitter.com', port=443): Read timed out. (read timeout=60)

I have seen other posts get around this by catching the error (see similar posts here and here), although catching the error and restarting my search would involve starting all over again with my list of tweets and collecting all the tweets within my target interval (24 hrs) would be impossible because the search would restart every 15 min due to errors.

Any ideas on how to get around this?

Community
  • 1
  • 1
Mohammed B
  • 305
  • 1
  • 4
  • 14
  • Maybe use the `page` parameter of `api.search`? (I haven't done it myself) – lrnzcig May 16 '16 at 14:31
  • @lrnzcig where does that parameter come from/what does it do? – Mohammed B May 16 '16 at 15:19
  • Take a look [here](http://docs.tweepy.org/en/v3.5.0/api.html). Actually, if you go straight with Twitter's REST api the [pagination mechanism](https://dev.twitter.com/ads/basics/pagination) is different, and I've used it with the package `twython`. But I guess internally `tweepy` should be doing the same thing. – lrnzcig May 16 '16 at 15:38

0 Answers0