【问题标题】:How to use tweepy STREAMING API with a proxy?如何将 tweepy STREAMING API 与代理一起使用?
【发布时间】:2014-05-01 22:49:08
【问题描述】:

我知道有一个将 REST API 与代理一起使用的补丁,它适用于我。但是 Streaming API 使用的 HTTPConnection 不能被 urllib 和 urllib2 模拟(据我所知)。有什么解决办法吗?

我尝试使用带端口的代理,但它不起作用。 在 streaming.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/statuses/filter.json?delimited=length

我得到这个错误作为回报 -

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

【问题讨论】:

    标签: python proxy httpconnection tweepy


    【解决方案1】:

    Tweepy 目前不支持使用代理。但是,对代理的支持应该会在接下来的几天内到来。我会用更多信息更新这个答案。

    【讨论】:

      【解决方案2】:

      终于找到了一个通过代理启用流式API的github补丁。它工作得很好!

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-22
        • 2014-10-24
        • 2011-05-21
        • 2018-06-27
        • 2018-08-16
        • 2012-06-13
        • 2019-01-30
        • 2016-05-06
        相关资源
        最近更新 更多