【发布时间】:2015-01-18 07:13:25
【问题描述】:
我想使用 tweepy API 从高音扬声器流式传输数据,我使用这个视频 (http://sentdex.com/sentiment-analysisbig-data-and-python-tutorials-algorithmic-trading/how-to-use-the-twitter-api-1-1-to-stream-tweets-in-python/) 来学习如何做到这一点,但不幸的是我收到了这个错误,
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey = 'credentials'
csecret = 'you'
atoken = 'should'
asecret = 'invalidate'
class listener(StreamListener):
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["car"])
这是错误:
Traceback (most recent call last):
File "C:/Users/azamb/PycharmProjects/PyStream/Stream.py", line 24, in <module>
twitterStream.filter(track=["car"])
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 418, in filter
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 335, in _start
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 275, in _run
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 244, in _run
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 287, in _read_loop
File "C:\Python34\lib\site-packages\tweepy-2.3-py3.4.egg\tweepy\streaming.py", line 167, in read_line
TypeError: Can't convert 'bytes' object to str implicitly
【问题讨论】:
-
说真的,您的凭据?
-
这是那个库的问题;它的 Python 3 支持不是很好。你应该提出来there。
-
我使用的是 Python 3.4 而不是 3.3