Twitter Error display bug in Python 3
[rainbowstream.git] / rainbowstream / util.py
CommitLineData
5531923e
LP
1import json
2
3from twitter.util import printNicely
8daad13d 4from .colors import *
5531923e
LP
5
6
9e38891f 7def detail_twitter_error(twitterException):
8daad13d 8 """
9 Display Twitter Errors nicely
10 """
5531923e 11 try:
62058715 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'))
5531923e 15 for m in loadedJson.get('errors', dict()):
9e38891f 16 info = "Error " + str(m.get('code')) + ": " + m.get('message')
17 printNicely(yellow(info))
62058715 18 except:
19 info = "Error: " + twitterException.response_data.decode('utf8')
9e38891f 20 printNicely(yellow(info))