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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With