From 32fa592d4ae535baf6e1cf17658d207fb656b16b Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Wed, 11 Apr 2018 19:39:23 -0700 Subject: [PATCH] Fix bug where streaming throws an exception after long use When we go to read the next line this method sometimes is return None (dead socket?). Guard against this with a check first before trying to strip the result. Fixes #1026 --- tweepy/streaming.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 43aa823..0ab71aa 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -313,11 +313,12 @@ class Stream(object): while self.running and not resp.raw.closed: length = 0 while not resp.raw.closed: - line = buf.read_line().strip() - if not line: + line = buf.read_line() + stripped_line = line.strip() if line else line # line is sometimes None so we need to check here + if not stripped_line: self.listener.keep_alive() # keep-alive new lines are expected - elif line.strip().isdigit(): - length = int(line) + elif stripped_line.isdigit(): + length = int(stripped_line) break else: raise TweepError('Expecting length, unexpected value found') -- 2.25.1