e8d3c74c0b4ba454ffc7fa4cf6c28824477bd66b
[rainbowstream.git] / rainbowstream / util.py
1 import json
2
3 from twitter.util import printNicely
4 from .colors import *
5
6
7 def detail_twitter_error(twitterException):
8 """
9 Display Twitter Errors nicely
10 """
11 try:
12 # twitterException.response_data can be byte string on Python 3
13 # or nornal dict on Python 2
14 loadedJson = json.loads(twitterException.response_data.decode('utf8'))
15 for m in loadedJson.get('errors', dict()):
16 info = "Error " + str(m.get('code')) + ": " + m.get('message')
17 printNicely(yellow(info))
18 except:
19 info = "Error: " + twitterException.response_data.decode('utf8')
20 printNicely(yellow(info))