2

I'm developing an application that collects information from YouTube via the YouTube APIv3. I'm using yapi package from github. I was working in Python2.7 and it worked fine.

But when I upgraded to Python 3.3 it suddenly gave me a certificate error.

Input

import yapi
Youtube = yapi.YoutubeAPI('API KEY')
Results = Youtube.general_search('keyword', max_results=10)
print(Results)

Output

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Python33\lib\site-packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "C:\Python33\lib\site-packages\urllib3\connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "C:\Python33\lib\site-packages\urllib3\connection.py", line 326, in connect
    ssl_context=context)
  File "C:\Python33\lib\site-packages\urllib3\util\ssl_.py", line 325, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Python33\lib\ssl.py", line 246, in wrap_socket
    _context=self)
  File "C:\Python33\lib\ssl.py", line 350, in __init__
    raise x
  File "C:\Python33\lib\ssl.py", line 346, in __init__
    self.do_handshake()
  File "C:\Python33\lib\ssl.py", line 553, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:548)

During handling of the above exception, another exception occurred:

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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/a227855/PycharmProjects/Youtube/Search.py", line 3, in <module>
    Results = Youtube.general_search('keyword', max_results=10)
  File "C:\Python33\lib\site-packages\yapi.py", line 36, in general_search
    objects = manager.api_request(api_url, params)
  File "C:\Python33\lib\site-packages\manager.py", line 47, in api_request
    con = requests.get(req_url)
  File "C:\Python33\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python33\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 502, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python33\lib\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:548)

Process finished with exit code 1

I had to change to Python 3.4 to try support other functions that I was using that only supported 3 and up.

Simeon Jaganyi
  • 43
  • 1
  • 1
  • 4

1 Answers1

-1

Try and change the manager.py line 47 from

con = requests.get(req_url)

to

 con = requests.get(req_url, verify=False)

There could be an issue with the SSL certificate.

Could be related to an issue I was having, using the requests library.

Danny Cullen
  • 1,782
  • 5
  • 30
  • 47
  • Yes as soon as I used another computer on another network (not behind a proxy) it worked fine. It's not advised to use vetify=False but you might not have much of a choice. – Danny Cullen Jul 28 '17 at 13:18
  • I can't explain that sorry. – Danny Cullen Jul 28 '17 at 13:30
  • When I make the change. I get this error `C:\Python33\lib\site-packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)` – Simeon Jaganyi Jul 28 '17 at 13:32
  • It should still work, it is only a warning I think. Also thinking about it, it could be that there is a different `cacert.pem` in `C:\Python27\lib\site-packages\certifi` compared to `C:\Python3\lib\site-packages\certifi` - https://github.com/certifi – Danny Cullen Jul 28 '17 at 13:42
  • Doing so, means that anyone with a privileged network position is able to trivially execute a man in the middle attack against a Python application using either of these HTTP clients, and change traffic at will. – stovfl Jul 28 '17 at 17:13
  • 1
    @DannyCullen I looked in to what you suggested about the certifi being different. So I downgraded my certifi 2017.7.21.1 to 2015.4.28 and it worked. It was mentioned here https://stackoverflow.com/questions/34646942/ssl3-get-server-certificate-certificate-verify-failed-on-python-when-requesting?rq=1 – Simeon Jaganyi Jul 28 '17 at 17:23