Tweepy流代理

时间:2016-11-02 03:59:24

标签: python tweepy

我正在尝试从特定区域的twitter中提取数据。但代码无法运行,它返回ConnectionError:无法建立新连接。

我在代码中找不到错误。所以我认为它必须配置请求。但我找不到在tweepy流中配置代理的解决方案。

虽然我尝试了一些修改代码的方法。但也有一个错误。所以我很感激有人可以给我任何建议。

import sys
import tweepy

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

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,proxy='127.0.0.1:1080')


class CustomStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        if 'python' in status.text.lower():
            print (status.text)

    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream

sapi = tweepy.streaming.Stream(auth, CustomStreamListener())    
sapi.filter(locations=[-6.38,49.87,1.77,55.81])

这是我得到的错误:

ConnectionError: HTTPSConnectionPool(host='stream.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/filter.json?delimited=length (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000000000D37F2E8>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))

0 个答案:

没有答案