2011-10-13 61 views
0

我正在嘗試訪問Streaming API,按照某些術語對其進行篩選,然後使用Tweepy打印出結果。但是我收到以下錯誤:Tweepy(twitter)socket.error Errno 104(連接重置對等)

File "/usr/local/lib/python2.6/dist-packages/tweepy-1.7.1-py2.6.egg/tweepy/streaming.py", line 110, in _run 
    resp = conn.getresponse() 
    File "/usr/lib/python2.6/httplib.py", line 986, in getresponse 
    response.begin() 
    File "/usr/lib/python2.6/httplib.py", line 391, in begin 
    version, status, reason = self._read_status() 
    File "/usr/lib/python2.6/httplib.py", line 349, in _read_status 
    line = self.fp.readline() 
    File "/usr/lib/python2.6/socket.py", line 397, in readline 
    data = recv(1) 
socket.error: [Errno 104] Connection reset by peer 

用下面的代碼...

import sys 
import tweepy 
from textwrap import TextWrapper 
from tweepy.streaming import StreamListener, Stream 

consumer_key  = '' 
consumer_secret  = '' 
access_token  = '' 
access_token_secret = '' 

auth1 = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth1.set_access_token(access_token, access_token_secret) 
api = tweepy.API(auth1) 

class StreamListener(tweepy.StreamListener): 
    status_wrapper = TextWrapper(width=60, initial_indent=' ', subsequent_indent=' ') 
    def on_status(self, status): 
     try: 
      print self.status_wrapper.fill(status.text) 
      print '\n %s %s via %s\n' % (status.author.screen_name, status.created_at, status.source) 
     except Exception, e: 
      pass 

def main(): 
    l = StreamListener() 
    streamer = tweepy.Stream(auth=auth1, listener=l, timeout=3000000000) 
    setTerms = ['hello', 'goodbye', 'goodnight', 'good morning'] 
    streamer.filter(None,setTerms) 

if __name__ == "__main__": 
    main() 

有誰知道如何解決呢?

謝謝...

回答

0

的原因是SSL,似乎現在的Twitter被迫...

+0

u能xplain並如何ü解決這個錯誤? – surendran

相關問題