gpt4 book ai didi

python - 带 Tweepy 的 StreamListener,TypeError

转载 作者:行者123 更新时间:2023-11-28 20:41:22 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com