Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'strip' #698

Closed
kodeine opened this issue Feb 2, 2016 · 10 comments
Closed

AttributeError: 'NoneType' object has no attribute 'strip' #698

kodeine opened this issue Feb 2, 2016 · 10 comments
Labels
Bug This is regarding a bug with the library

Comments

@kodeine
Copy link

kodeine commented Feb 2, 2016

i've been getting this error for a while.

Traceback (most recent call last):
  File "engine/twitter.py", line 139, in <module>
    stream.filter(track=['#blood',], languages=['en'])
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 445, in filter
    self._start(async)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 361, in _start
    self._run()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 263, in _run
    self._read_loop(resp)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 313, in _read_loop
    line = buf.read_line().strip()
AttributeError: 'NoneType' object has no attribute 'strip'
@kodeine
Copy link
Author

kodeine commented Feb 4, 2016

Another one,

Traceback (most recent call last):
  File "engine/twitter.py", line 139, in <module>
    stream.filter(track=['#blood',], languages=['en'])
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 445, in filter
    self._start(async)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 361, in _start
    self._run()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 263, in _run
    self._read_loop(resp)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 324, in _read_loop
    self._data(next_status_obj)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 297, in _data
    if self.listener.on_data(data) is False:
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 50, in on_data
    data = json.loads(raw_data)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

@rxcomm
Copy link

rxcomm commented Feb 5, 2016

This patch fixes it for me.

diff --git a/tweepy/streaming.py b/tweepy/streaming.py
index ad7944c..6818f58 100644
--- a/tweepy/streaming.py
+++ b/tweepy/streaming.py
@@ -310,7 +310,10 @@ class Stream(object):
         while self.running and not resp.raw.closed:
             length = 0
             while not resp.raw.closed:
-                line = buf.read_line().strip()
+                try:
+                    line = buf.read_line().strip()
+                except AttributeError:
+                    pass
                 if not line:
                     self.listener.keep_alive()  # keep-alive new lines are expected
                 elif line.isdigit():

@karelbilek
Copy link

I am getting this too. I hope you won't be against it @rxcomm if I add this as a pull request

@karelbilek karelbilek mentioned this issue Mar 8, 2016
@remram44
Copy link
Contributor

I'm also getting this.

@karelbilek
Copy link

it's fixed in #694 , nobody is merging PR here

benfei pushed a commit to benfei/tweepy that referenced this issue Oct 11, 2016
If the stream is closed while reading, act as if it was closed before reading began.

This resloves tweepy#576, resloves tweepy#698 and resolves tweepy#734.

Similar to tweepy#694, tweepy#780.
sheshnath08 added a commit to sheshnath08/tweepy that referenced this issue Oct 23, 2016
In streaming.py at line# 313:
when buf.read_line() is called, it may return NoneType and when applying strip() it will generate AttribiteError. Hence to fix this placing the line into try-except block.
@patrick-brian-mooney
Copy link

Still affects me. Hoping a new version is posted to PyPI soon!

@wuhland
Copy link

wuhland commented Oct 13, 2017

I just got this error. Somebody please give somebody access to this repo so they can PR and also post to PyPI

@joshua-barber
Copy link

@Aaron1011 (as you closed the issue) can you clarify if the fix was applied/posted to PyPI?

I've been running a data collection script since January and, checking the logs, its been hitting this issue pretty regularly. Not sure what the commonality is between the erroring tweets either.

@paldana
Copy link

paldana commented Apr 4, 2018

Hello @joshua-barber,

Were you able to catch the error, at least? I'm thinking of a work around for my project wherein I will just catch this particular error and just restart the stream data collection. Not the nicest solution, but it'll work for me.

Regards,

Paul

@Harmon758
Copy link
Member

@patrick-brian-mooney @wuhland @joshua-barber @paldana
This specific fix (c1eddf1) was in the v3.6.0 release.
However, the error persisted (see #1026). This was then fixed with 32fa592 (#1027) in 3.7.0.

@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library
Projects
None yet
Development

No branches or pull requests

9 participants