带 Tweepy 的 StreamListener,TypeError
StreamListener with Tweepy, TypeError
我正在尝试从特定 hastags 中恢复推文。我正在使用 Python 2.7.6 和 Tweepy 来收听 hastag。在这篇文章之后:Introduction to tweepy, Twitter for Python 我最终得到:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
access_token = ""
access_token_secret = ""
consumer_secret = ""
consumer_key = ""
class StdOutListener(StreamListener):
def on_status(self, status):
# Prints the text of the tweet
print('Tweet text: ' + status.text)
return true
def on_error(self, status_code):
print('Got an error with status code: ' + str(status_code))
return True # To continue listening
def on_timeout(self):
print('Timeout...')
return True # To continue listening
if __name__ == '__main__':
listener = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, listener)
stream.filter(track=['#apple'])
但是当我 运行 脚本时,出现以下错误:
File "test.py", line 40, in
stream.filter(track=['#apple'])
File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 430, in filter
self._start(async)
File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 346, in _start
self._run()
File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 286, in _run
raise exception
TypeError: cannot make memory view because object does not have the buffer interface
有人知道为什么吗?
这似乎是一个已知问题 #659。
如果您将 requests
降级到 2.7 应该可以解决这个问题。
pip uninstall requests
pip install requests==2.7
我正在尝试从特定 hastags 中恢复推文。我正在使用 Python 2.7.6 和 Tweepy 来收听 hastag。在这篇文章之后:Introduction to tweepy, Twitter for Python 我最终得到:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
access_token = ""
access_token_secret = ""
consumer_secret = ""
consumer_key = ""
class StdOutListener(StreamListener):
def on_status(self, status):
# Prints the text of the tweet
print('Tweet text: ' + status.text)
return true
def on_error(self, status_code):
print('Got an error with status code: ' + str(status_code))
return True # To continue listening
def on_timeout(self):
print('Timeout...')
return True # To continue listening
if __name__ == '__main__':
listener = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, listener)
stream.filter(track=['#apple'])
但是当我 运行 脚本时,出现以下错误:
File "test.py", line 40, in stream.filter(track=['#apple']) File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 430, in filter self._start(async) File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 346, in _start self._run() File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 286, in _run raise exception TypeError: cannot make memory view because object does not have the buffer interface
有人知道为什么吗?
这似乎是一个已知问题 #659。
如果您将 requests
降级到 2.7 应该可以解决这个问题。
pip uninstall requests
pip install requests==2.7