Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a timeout for tweepy

I'm using tweepy for sending tweets, so far so good. in the last 10 minutes, for some reason, twitter.com isn't working for me, but that's not the issue. The issue is, that in this situation,

api.update_status(msg)

takes a loooong time(1 min approximately) before the error raised.

 [Errno 10060] A connection attempt failed..

How can I set the time out for lets say 3-5 sec, so if after 5 sec twitter.com isn't working, it will raise error 10060 right away?

I tried, without success:

api.update_status(msg, timeout=5)
like image 558
oren Avatar asked Jul 16 '14 04:07

oren


People also ask

What is wait on rate limit Tweepy?

But keep in mind that Twitter levies a rate limit on the number of requests made to the Twitter API. To be precise, 900 requests/15 minutes are allowed; Twitter feeds anything above that an error.

What is RPP in Tweepy?

The number of tweets to return per page, up to a maximum of 100. Defaults to 15. This was formerly the "rpp" parameter in the old Search API.

Is Tweepy deprecated?

1 endpoint this method uses is now deprecated and will be retired on October 29, 2022. Twitter API v2 can be used instead with AsyncStreamingClient.

What is Wait_on_rate_limit?

wait_on_rate_limit – Whether or not to automatically wait for rate limits to replenish. wait_on_rate_limit_notify – Whether or not to print a notification when Tweepy is waiting for rate limits to replenish.


1 Answers

You have to set the timeout attribute when initializing the API, not when using a status method:

api = tweepy.API(timeout=5) #default=60

For some reason this option isn't listed in the official documentation, but you can find it in the actual code.

like image 51
dwitvliet Avatar answered Oct 26 '22 06:10

dwitvliet