如何用Twython解决OpenSSL空错误?

时间:2018-09-30 15:48:16

标签: python openssl raspberry-pi twython

我尝试通过简单的代码使用TwythonStreamer:

from twython import TwythonStreamer

class MyStreamer(TwythonStreamer):
def on_success(self, data):
    if 'text' in data:
        print(data['text'])

def on_error(self, status_code, data):
    print(status_code, data)
    self.disconnect()       

stream = MyStreamer('xxxx',
                'xxxx',
                'xxxx',
                'xxxx')

stream.statuses.filter(track = 'twitter')

然后我运行程序:

sudo python 2vols.py

但是我有这个消息:

Traceback (most recent call last):
File "2vols.py", line 17, in <module>
stream.statuses.filter(track = 'twitter')
File "/usr/lib/python2.7/dist-packages/twython/streaming/types.py", line 66, in filter
self.streamer._request(url, 'POST', params=params)
File "/usr/lib/python2.7/dist-packages/twython/streaming/api.py", line 139, in _request
response = _send(retry_counter)
File "/usr/lib/python2.7/dist-packages/twython/streaming/api.py", line 123, in _send
response = func(url, **requests_args)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 535, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 594, in urlopen
chunked=chunked)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 350, in _make_request
self._validate_conn(conn)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 837, in _validate_conn
conn.connect()
File "/usr/lib/python2.7/dist-packages/urllib3/connection.py", line 323, in connect
ssl_context=context)
File "/usr/lib/python2.7/dist-packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
context.load_verify_locations(ca_certs, ca_cert_dir)
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 392, in load_verify_locations
self._ctx.load_verify_locations(cafile, capath)
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 525, in load_verify_locations
_raise_current_error()
File "/usr/lib/python2.7/dist-packages/OpenSSL/_util.py", line 48, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: []

OpenSSL出现问题,但错误消息为空。

我确保已使用sudo apt-get install openssl安装了OpenSSL

您了解发生了什么事吗?

谢谢!

0 个答案:

没有答案