From 64b134999371cbb6a07e12597213d331ab2b16a9 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Fri, 24 May 2013 16:17:50 -0400 Subject: [PATCH] Python 3 compat --- test_twython.py | 2 +- twython/streaming/api.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test_twython.py b/test_twython.py index c867834..1e706a5 100644 --- a/test_twython.py +++ b/test_twython.py @@ -102,7 +102,7 @@ class TwythonAPITestCase(unittest.TestCase): counter = 0 while counter < 2: counter += 1 - result = search.next() + result = next(search) new_id_str = int(result['id_str']) if counter == 1: prev_id_str = new_id_str diff --git a/twython/streaming/api.py b/twython/streaming/api.py index 1a77ec5..6414020 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -1,5 +1,5 @@ from .. import __version__ -from ..compat import json +from ..compat import json, is_py3 from ..exceptions import TwythonStreamError from .types import TwythonStreamerTypes @@ -93,7 +93,11 @@ class TwythonStreamer(object): break if line: try: - self.on_success(json.loads(line)) + if not is_py3: + self.on_success(json.loads(line)) + else: + line = line.decode('utf-8') + self.on_success(json.loads(line)) except ValueError: raise TwythonStreamError('Response was not valid JSON, \ unable to decode.')