Tweepy(twitter)socket.error Errno 104(连接由同行重置)

时间:2011-10-13 13:26:58

标签: twitter twitter-oauth tweepy

我正在尝试访问Streaming API,按照某些术语对其进行过滤,然后使用Tweepy打印出结果。但是我收到以下错误:

 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()

有谁知道如何解决它?

...谢谢

1 个答案:

答案 0 :(得分:0)

原因是SSL,现在似乎是由推特强迫......