While trying to execute the code for streaming tweets based on a filter i am getting this below mentioned error.
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'))
Please find below the code i have used.
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]])
I am using python 2.6.6 on a CentOS6.3
The problem is your proxy connection is failing and tweepy doesn't have proxy support. You can use twitterAPI which has inbuilt proxy support or check this . Its a tweepy fork with proxy implemented
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.