Skip to content

Commit d553391

Browse files
author
Ankit Agarwal
committed
Handling exceptions while calling twitter api to update status
with/without media. f.e.: When character limit exceeds 140, the api call returns an exception. The exception is handled and the error is printed. This signifies an unsuccessful operation.
1 parent d430420 commit d553391

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tweeter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ def tweetthis(type):
1212
if type == "text":
1313
print "Enter your tweet "+user.name
1414
tweet = raw_input()
15-
api.update_status(tweet)
15+
try:
16+
api.update_status(tweet)
17+
except Exception as e:
18+
print e
19+
return
1620
elif type == "pic":
1721
print "Enter pic path "+user.name
1822
pic = os.path.abspath(raw_input())
1923
print "Enter status "+user.name
2024
title = raw_input()
21-
api.update_with_media(pic, status=title)
25+
try:
26+
api.update_with_media(pic, status=title)
27+
except Exception as e:
28+
print e
29+
return
2230

2331
print "\n\nDONE!!"
2432

0 commit comments

Comments
 (0)