我认为我的大学最近更改了有关Twitter流API的防火墙或过滤协议。但是,要为我提供更多信息,我将不得不弄清楚细节。

好的,下面是从Twitter流中收集数据的最简单的程序:

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener


ckey="[OMITED]"
csecret="[OMITED]"
atoken="[OMITED]"
asecret="[OMITED]"

class listener(StreamListener):

    def on_data(self, data):
        print(data)
        return(True)

    def on_error(self, status):
        print status

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

twitterStream = Stream(auth, listener())
twitterStream.filter(track=["car"])


当我在笔记本电脑/家用台式机上运行此程序时,它可以正常工作。但是,我有一个用于数据收集的大学计算机设置,它会产生以下错误:

Traceback (most recent call last):
  File "test.py", line 25, in <module>
    twitterStream.filter(track=["car"])
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 228, in filter
    self._start(async)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 172, in _start
    self._run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 106, in _run
    conn.connect()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1278, in connect
    server_hostname=server_hostname)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket
    _context=self)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__
    self.do_handshake()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)


现在,我可以打开Safari并浏览网络。此外,像这样的数据收集可以正常工作(从一个月前开始)。该错误表明SSL证书无法通过验证(但奇怪的是原始OAuth似乎可以正常工作-这是过滤器命令引发的错误)。如果那是因为已放置中间证书,是否有办法使其吐出?还是端口被阻塞了?基本上,有没有一种方法可以获取更多详细信息,所以我可以上大学说:“您正在阻止X”?

有什么建议么?

最佳答案

我已经解决了情况。与使用Digicerts签名的SSL站点有关的错误。

08-27 22:32