From 620587157c57f179960c2576b591819056f813bb Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Thu, 23 Oct 2014 13:39:08 +0900 Subject: [PATCH] Twitter Error display bug in Python 3 --- docs/conf.py | 4 ++-- rainbowstream/rainbow.py | 2 ++ rainbowstream/util.py | 8 +++++--- setup.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 985bdd5..628c223 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -48,9 +48,9 @@ copyright = u'2014, Vu Nhat Minh' # built documents. # # The short X.Y version. -version = '1.1.8' +version = '1.1.9' # The full version, including alpha/beta/rc tags. -release = '1.1.8' +release = '1.1.9' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 206f84d..f06b510 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -2073,6 +2073,8 @@ def stream(domain, args, name='Rainbow Stream'): printNicely( magenta("We have connection problem with twitter'stream API right now :(")) detail_twitter_error(e) + sys.stdout.write(g['decorated_name'](c['PREFIX'])) + sys.stdout.flush() def fly(): diff --git a/rainbowstream/util.py b/rainbowstream/util.py index a3cd127..e8d3c74 100644 --- a/rainbowstream/util.py +++ b/rainbowstream/util.py @@ -9,10 +9,12 @@ def detail_twitter_error(twitterException): Display Twitter Errors nicely """ try: - loadedJson = json.loads(twitterException.response_data) + # twitterException.response_data can be byte string on Python 3 + # or nornal dict on Python 2 + loadedJson = json.loads(twitterException.response_data.decode('utf8')) for m in loadedJson.get('errors', dict()): info = "Error " + str(m.get('code')) + ": " + m.get('message') printNicely(yellow(info)) - except ValueError: - info = "Error: " + twitterException.response_data + except: + info = "Error: " + twitterException.response_data.decode('utf8') printNicely(yellow(info)) diff --git a/setup.py b/setup.py index 85973a7..0e34739 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '1.1.8' +version = '1.1.9' # Require install_requires = [ -- 2.25.1