在尝试基于过滤器执行流媒体推文的代码时,我得到了下面提到的错误。
Traceback (most recent call last):
File "new5.py", line 37, in <module> stream.filter(track=[sys.argv[1]])
File "/usr/lib/python2.6/site-packages/tweepy/streaming.py", line 428, in filter self._start(async)
File "/usr/lib/python2.6/site-packages/tweepy/streaming.py", line 346, in _start self._run() File "/usr/lib/python2.6/site-packages/tweepy/streaming.py", line 239, in _run verify=self.verify)
File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 461, in request resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs)
File "/usr/lib/python2.6/site-packages/requests/adapters.py", line 415, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
请在下面找到我使用的代码。
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import sys
import json
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
class StdOutListener(StreamListener):
def on_data(self, data):
print('tweet: ' + json.loads(data)['text'])
return True
def on_error(self, status):
print(status)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python %s filter_name" % sys.argv[0])
sys.exit(1)
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=[sys.argv[1]])
我在CentOS6.3上使用python 2.6.6