tweepy ssl证书无法发送请求

时间:2017-09-15 13:44:11

标签: python-3.x ssl tweepy

任何人都有关于tweepy和ssl的问题吗?我想过手动更改tweepy代码,但不确定究竟需要更改什么。我设置了我的OAuth并且正在调用tweepy.API(auth)。我尝试在那里添加一个verify = false,但是这会引发一个错误,因为我认为在当前版本的tweepy中不允许这样做。

这是我的错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 810, in _prepare_proxy
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 326, in connect
    ssl_context=context)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 325, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
    _context=self, _session=session)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
    self.do_handshake()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 630, in urlopen
    raise SSLError(e)
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tweepy/binder.py", line 187, in execute
    proxies=self.api.proxy)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 502, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "appauth.py", line 17, in <module>
    print(api.favorites())
  File "/usr/local/lib/python3.6/site-packages/tweepy/binder.py", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python3.6/site-packages/tweepy/binder.py", line 189, in execute
    raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

2 个答案:

答案 0 :(得分:0)

尝试安装下一个软件包,

pip install pyOpenSSL pyasn1 certifi

尝试再次运行代码。

答案 1 :(得分:0)

我遇到了SSL问题,我必须导入此lib才能解决问题。

import urllib3.contrib.pyopenssl

urllib3.contrib.pyopenssl.inject_into_urllib3()