Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
2767e6c1
Commit
2767e6c1
authored
Dec 31, 2014
by
grocerheist
Browse files
Add a Few More Pointers to streaming_how_to.rst to cover Async and error handling.
parent
976acd98
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/streaming_how_to.rst
View file @
2767e6c1
.. _streaming_how_to:
.. _streaming_how_to:
.. _Twitter Streaming API Documentation: https://dev.twitter.com/streaming/overview
.. _Twitter Streaming API Documentation: https://dev.twitter.com/streaming/overview
.. _Twitter Response Codes Documentation: https://dev.twitter.com/overview/api/response-codes
*********************
*********************
Streaming With Tweepy
Streaming With Tweepy
...
@@ -79,5 +80,32 @@ the word *python*. The **track** parameter is an array of search terms to stream
...
@@ -79,5 +80,32 @@ the word *python*. The **track** parameter is an array of search terms to stream
myStream.filter(track=['python'])
myStream.filter(track=['python'])
A Few More Pointers
===================
Async Streaming
---------------
Streams not terminate unless the connection is closed, blocking the thread.
Tweepy offers a convenient **async** parameter on **filter** so the stream will run on a new
thread. For example ::
myStream.filter(track=['python'], async=True)
Handling Errors
---------------
When using Twitter's streaming API one must be careful of the dangers of
rate limiting. If clients exceed a limited number of attempts to connect to the streaming API
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.::
class MyStreamListener(tweepy.StreamListener):
def on_error(self, status_code):
if status_code == 420:
#returning False in on_data disconnects the stream
return False
For more information on error codes from the twitter api see `Twitter Response Codes Documentation`_.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment