TwitterStream can disconnect
esdalmaijer opened this issue · 1 comments
The Twitter library will sometimes return {'hangup':True}
instead of a typical tweet dictionary. This occurs on a Stream SSLError (see this commit in the twitter
library). Calling on an iterator after this disconnect will cause a StopIteration
exception.
This will crash the _autoreplythread
, which assumes certain keys will be in the tweet dict. In addtion, it relies on a working TwitterStream. Two changes are necessary to fix this:
- Check before line 690 whether
'hangup' in tweet.keys()
. If it is, the TwitterStream should be restarted (see change 2), and the current tweet should not be processed. - Add a
_reanimate
method to restart the Twitter connection. To be safe, restart both_t
(Twitter login) and_ts
(TwitterStream).
NOTE: A call to _reanimate
should also be added to _autotweet
's try-except for posting a new Tweet.
This commit should fix this issue. If it doesn't, it'll be because the OAuth expired. The solution to that would be to store the access tokens, but that would be a bit iffy... (We'll worry about that when the time comes.)