t4.py 984 Bytes
Newer Older
Josh Roesslein's avatar
Josh Roesslein committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import tweepy

""" Tutorial 4 -- Errors

Errors are going to happen sooner or later in your applications.
This tutorial will show you how to properly catch these errors in 
Tweepy and handle them gracefully in your application.
"""

""" TweepError

Tweepy uses a single exception: tweepy.TweepError.
When ever something goes wrong this exception will be raised.
Here is an example:
"""
try:
Josh Roesslein's avatar
Josh Roesslein committed
17
    tweepy.api.update_status('this will fail since we are not authenticated!')
Josh Roesslein's avatar
Josh Roesslein committed
18
except tweepy.TweepError, e:
Josh Roesslein's avatar
Josh Roesslein committed
19
    print 'Failed to update! %s' % e
Josh Roesslein's avatar
Josh Roesslein committed
20
21
22

"""
TweepError's can be casted to string format which will
Josh Roesslein's avatar
Josh Roesslein committed
23
give details as to what went wrong.
Josh Roesslein's avatar
Josh Roesslein committed
24
25
26
27
28
29
30
31
32
33
34
35
36
The main reasons an exception will be raised include:

  -HTTP request to twitter failed
  -Model failed validation
  -Trying to use an authenticated API endpoint w/o authenticating
  -Invalid parameters supplied to API methods
  -Authentication failures

Be sure to keep a look out for these exceptions and handle them properly.
"""

""" The End """