python-3.x - tweepy ssl 证书发送请求失败

标签 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)

最佳答案

尝试安装下一个包,

pip install pyOpenSSL pyasn1 certifi

然后再次尝试运行代码。

关于python-3.x - tweepy ssl 证书发送请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46241075/

相关文章:

python - 将 Autocomplete=off 应用到 Django 密码重置确认表单

python - 优化 pandas 数据帧应用于解码 CAN 帧 - 迭代行

python - bytes 没有 __bytes__ 方法

ssl - Windows 10 WebDAV 中断到 Internet 服务(例如托管服务提供商)

c# - 如何在 Windows Phone 8.1 上实现证书锁定

python - 使用 tweepy 游标时,捕获容量过大错误的最佳做法是什么?

python - Twitter API - 获取关注者的关注者数量

html - 如何根据 BeautifulSoup 的特定链接抓取文本?

ssl - 通过 https 从受 IP-SSL 保护的 Azure Web 应用程序下载页面内容