我正在尝试进行Twitter搜索并获取有关特定关键字的推文。我有以下代码。
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey = 'acVL....'
csecret = 'qq0W1qdIr24XzCuX...'
atoken = '439474342-ZJfFqM4oZ8Y8....p'
asecret = 'Y9MKssDKs8IHIJMhNJCmyUCE3...'
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=["sample_word"])
当我尝试运行此代码时,我收到以下错误。
Traceback (most recent call last):
File "tw.py", line 22, in <module>
twitterStream.filter(track=["secretcv"])
File "/usr/local/lib/python2.7/dist-packages/tweepy-2.3.0-py2.7.egg/tweepy/streaming.py", line 316, in filter
File "/usr/local/lib/python2.7/dist-packages/tweepy-2.3.0-py2.7.egg/tweepy/streaming.py", line 237, in _start
File "/usr/local/lib/python2.7/dist-packages/tweepy-2.3.0-py2.7.egg/tweepy/streaming.py", line 157, in _run
File "/usr/lib/python2.7/httplib.py", line 1172, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
我错过了什么吗?欢迎提出任何建议