Commit 5720a0b1 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Update tutorial 4 to demo retry request feature.

parent c7837b0e
......@@ -7,6 +7,7 @@ during upgrade will be listed here.
+ Added automatic request re-try feature
Example: API.friends(retry_count=5, retry_delay=10)
Retry up to 5 times with a delay of 10 seconds between each attempt.
See tutorial/t4.py for more an example.
+ Added cursor parameter to API.friends and API.followers methods.
Note: page parameter is being deprecated by twitter on 10/26
+ Update parsing to handle cursor responses.
......
......@@ -32,5 +32,33 @@ The main reasons an exception will be raised include:
Be sure to keep a look out for these exceptions and handle them properly.
"""
"""
If Twitter returns an error response you may wish to retry the request
again. To help make this easier Tweepy allows you to configure it to do
this for you automatically when such error codes are returned.
Here is an example of performing a request and retrying if it fails.
We will tell Tweepy to only attempt up to 5 retries and wait 5 seconds
between each attempt.
"""
try:
tweepy.api.friends_timeline(retry_count=5, retry_delay=5)
except tweepy.TweepError, e:
# If all 5 attempts fail a TweepError will be thrown
print 'Failed to get timeline: %s' % e
"""
By default Tweepy will only retry when a status code of 500, 502, or 503
is returned by Twitter. All other codes result in an immediate TweepError.
If we do not provide a retry_delay Tweepy by default does not wait between requests.
Let's say we want to retry on status code responses of 400 only.
Here is how we do that...
"""
try:
tweepy.api.user_timeline('twitter', retry_count=3, retry_delay=5, retry_errors=[400])
except tweepy.TweepError, e:
print 'Failed to get timeline: %s' % e
""" The End """
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment