diff --git a/AUTHORS.rst b/AUTHORS.rst index e155804..461d25d 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -40,3 +40,5 @@ Patches and Suggestions - `Greg Nofi `_, fixed using built-in Exception attributes for storing & retrieving error message - `Jonathan Vanasco `_, Debugging support, error_code tracking, Twitter error API tracking, other fixes - `DevDave `_, quick fix for longs with helper._transparent_params +- `Ruben Varela Rosa `_, Fixed search example +>>>>>>> Update stream example, update AUTHORS for future example fix diff --git a/HISTORY.rst b/HISTORY.rst index a56f395..bdeb0fc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,7 @@ History - Updated some internal API code, ``__init__`` didn't need to have ``self.auth`` and ``self.headers`` because they were never used anywhere else but the ``__init__`` - Added ``disconnect`` method to ``TwythonStreamer``, allowing users to disconnect as they desire - Updated ``TwythonStreamError`` docstring, also allow importing it from ``twython`` +- No longer raise ``TwythonStreamError`` when stream line can't be decoded. Instead, sends signal to ``TwythonStreamer.on_error`` 2.10.0 (2013-05-21) ++++++++++++++++++ diff --git a/examples/stream.py b/examples/stream.py index 0e23a09..a571711 100644 --- a/examples/stream.py +++ b/examples/stream.py @@ -3,7 +3,8 @@ from twython import TwythonStreamer class MyStreamer(TwythonStreamer): def on_success(self, data): - print data + if 'text' in data: + print data['text'].encode('utf-8') # Want to disconnect after the first result? # self.disconnect() diff --git a/test_twython.py b/test_twython.py index 1e706a5..16598c1 100644 --- a/test_twython.py +++ b/test_twython.py @@ -154,22 +154,6 @@ class TwythonAPITestCase(unittest.TestCase): status = self.api.update_status(status='Test post just to get deleted :(') self.api.destroy_status(id=status['id_str']) - def test_retweet(self): - '''Test retweeting a status succeeds''' - retweet = self.api.retweet(id='99530515043983360') - self.api.destroy_status(id=retweet['id_str']) - - def test_retweet_twice(self): - '''Test that trying to retweet a tweet twice raises a TwythonError''' - tweets = self.api.search(q='twitter').get('statuses') - if tweets: - retweet = self.api.retweet(id=tweets[0]['id_str']) - self.assertRaises(TwythonError, self.api.retweet, - id=tweets[0]['id_str']) - - # Then clean up - self.api.destroy_status(id=retweet['id_str']) - def test_get_oembed_tweet(self): '''Test getting info to embed tweet on Third Party site succeeds''' self.api.get_oembed_tweet(id='99530515043983360') diff --git a/twython/streaming/api.py b/twython/streaming/api.py index 6414020..a246593 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -13,6 +13,7 @@ class TwythonStreamer(object): def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret, timeout=300, retry_count=None, retry_in=10, headers=None): """Streaming class for a friendly streaming user experience + Authentication IS required to use the Twitter Streaming API :param app_key: (required) Your applications key :param app_secret: (required) Your applications secret key @@ -99,8 +100,9 @@ class TwythonStreamer(object): line = line.decode('utf-8') self.on_success(json.loads(line)) except ValueError: - raise TwythonStreamError('Response was not valid JSON, \ - unable to decode.') + self.on_error(response.status_code, 'Unable to decode response, not vaild JSON.') + + response.close() def on_success(self, data): """Called when data has been successfull received from the stream