如何使用代理使用Tweepy Streaming API



我知道有一个用于使用代理的REST API的补丁,对我有用。但是流媒体API使用了urllib和urllib2无法模拟的HTTPConnection(据我所知)。有什么解决方案吗?

我尝试使用端口代理,但它不起作用。在stream.py文件中,第153行。

    if self.scheme == "http":
                conn = httplib.HTTPConnection(self.api.proxy_host,self.api.proxy_port, timeout=self.timeout)
            else:
                conn = httplib.HTTPSConnection(self.api.proxy_host,self.api.proxy_port,timeout=self.timeout)
            self.auth.apply_auth(url, 'POST', self.headers, self.parameters)
            print conn.host
            conn.connect()
            conn.request('POST', self.scheme+'://'+self.host+self.url, self.body, headers=self.headers)
            resp = conn.getresponse()

和," self.scheme '://' self.host self.url" 对应于-https://stream.twitter.com/1.1.1.1/statuses/filter.json?界定=长度

我在回报中得到此错误 -

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2538,    in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-3-4798d330f7cd>", line 1, in <module>
execfile('main.py')
File "main.py", line 130, in <module>
streamer.filter(track = ['AAP'])
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 305, in filter
self._start(async)
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 242, in _start
self._run()
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 159, in _run
conn.connect()
File "/usr/lib/python2.7/httplib.py", line 1161, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
    self._sslobj.do_handshake()
    SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL      routines:SSL23_GET_SERVER_HELLO:unknown protocol

当前不支持使用代理。但是,对代理的支持应在接下来的几天内到来。我将使用更多信息更新此答案。

最终找到了通过代理启用流api的github补丁。它可以正常工作!

https://github.com/shogo82148/tweepy/blob/64c62666018920E0E0E0E36C6C6D8D1600ADB6CAA0840DE/tweepy/tweepy/tweepy/streaming.py.py.py

相关内容

  • 没有找到相关文章

最新更新