python - 带 Tweepy 的 StreamListener,TypeError

标签 python python-2.7 api twitter tweepy

我正在尝试从特定 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

关于python - 带 Tweepy 的 StreamListener,TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33610103/

相关文章:

python - 为什么 Python 2.7 namedtuple 实现了 __dict__?

python - 使用 os.mkdir 与 os.system ("mkdir"的好处)

api - Scala API 2.10.* : Function2. 然后发生了什么?

python - 无法从延迟加载网站获取某些标签

python - 正则表达式匹配第一个和最后一个单词或任何单词

python - 为什么更新一个字典对象会影响其他对象?

.net - AutoCAD .NET API - 中断关闭托盘/窗口/用户控制命令

python - 使用 pymysql 从服务器中逐行获取行

python - 版本号 (vX.X.X) 的正则表达式不起作用

api - golang 反模式中的基本 API?