Commit 32fa592d authored by Josh Roesslein's avatar Josh Roesslein

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
parent 25e445de
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment