From 5531923ea428470228d145d3c89fee0aecbe6e78 Mon Sep 17 00:00:00 2001 From: Lukas Pohlreich Date: Wed, 22 Oct 2014 12:17:21 +0200 Subject: [PATCH] Added util function to print twitter errors --- rainbowstream/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 rainbowstream/util.py diff --git a/rainbowstream/util.py b/rainbowstream/util.py new file mode 100644 index 0000000..232845c --- /dev/null +++ b/rainbowstream/util.py @@ -0,0 +1,16 @@ +import json + +from twitter.util import printNicely + +from .colors import magenta + + +def printTwitterErrors(twitterException): + try: + loadedJson = json.loads(twitterException.response_data) + for m in loadedJson.get('errors', dict()): + printNicely( + magenta("Error " + str(m.get('code')) + ": " + m.get('message'))) + except ValueError: + printNicely( + magenta( "Error: " + twitterException.response_data)) -- 2.25.1