1

Anyone have issues with tweepy and ssl? I thought about manually changing the tweepy code, but not sure what exactly would need to be changed. I set up my OAuth and am calling tweepy.API(auth). I tried to add a verify=false in there, but that throws an error as I don't think it is allowed in the current version of tweepy.

Here is my error:

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)
user6754289
  • 437
  • 1
  • 8
  • 26

2 Answers2

0

Try to install the next packages,

pip install pyOpenSSL pyasn1 certifi

And try to run code again.

  • 1
    That gave me a bad handshake too: (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)) – user6754289 Sep 15 '17 at 14:05
  • If you using Mac OS, try `which openssl` if you don't have openssl yet, please try to install `brew install openssl`, and run code again;) –  Sep 15 '17 at 14:12
  • You should to check https://stackoverflow.com/questions/37349419/tweepy-sslerror-regarding-ssl-certificate or https://stackoverflow.com/questions/10667960/python-requests-throwing-up-sslerror –  Sep 15 '17 at 14:29
0

I had SSL issues and I had to import this lib to fix the issue.

import urllib3.contrib.pyopenssl

urllib3.contrib.pyopenssl.inject_into_urllib3()
Sudheesh Singanamalla
  • 2,283
  • 3
  • 19
  • 36