Twitter Error display bug in Python 3
[rainbowstream.git] / rainbowstream / util.py
... / ...
CommitLineData
1import json
2
3from twitter.util import printNicely
4from .colors import *
5
6
7def 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))