Skip to content

Commit

Permalink
Merge pull request #585 from wjt/streaming-docs
Browse files Browse the repository at this point in the history
Better documentation for StreamListener.on_error
  • Loading branch information
Aaron1011 committed Nov 6, 2016
2 parents 06c06c6 + bb1eaa1 commit 5fa066b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Contents:
auth_tutorial.rst
code_snippet.rst
cursor_tutorial.rst
streaming_how_to.rst
api.rst
streaming_how_to.rst

Expand Down
14 changes: 10 additions & 4 deletions docs/streaming_how_to.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.. _streaming_how_to:
.. _Twitter Streaming API Documentation: https://dev.twitter.com/streaming/overview
.. _Twitter Streaming API Connecting Documentation: https://dev.twitter.com/streaming/overview/connecting
.. _Twitter Response Codes Documentation: https://dev.twitter.com/overview/api/response-codes

*********************
Expand Down Expand Up @@ -99,15 +100,20 @@ rate limiting. If clients exceed a limited number of attempts to connect to the
in a window of time, they will receive error 420. The amount of time a client has to wait after receiving error 420
will increase exponentially each time they make a failed attempt.

Tweepy's **Stream Listener** usefully passes error messages to an **on_error** stub. We can use **on_error** to
catch 420 errors and disconnect our stream. ::
Tweepy's **Stream Listener** passes error codes to an **on_error** stub. The
default implementation returns **False** for all codes, but we can override it
to allow Tweepy to reconnect for some or all codes, using the backoff
strategies recommended in the `Twitter Streaming API Connecting
Documentation`_. ::

class MyStreamListener(tweepy.StreamListener):

def on_error(self, status_code):
if status_code == 420:
#returning False in on_data disconnects the stream
#returning False in on_error disconnects the stream
return False

For more information on error codes from the twitter api see `Twitter Response Codes Documentation`_.
# returning non-False reconnects the stream, with backoff.

For more information on error codes from the Twitter API see `Twitter Response Codes Documentation`_.

0 comments on commit 5fa066b

Please sign in to comment.