ssl,urllib3,请求.exceptions.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:548)

时间:2017-07-28 12:49:43

标签: python ssl youtube-api ssl-certificate

我正在开发一个通过YouTube APIv3从YouTube收集信息的应用程序。我正在使用github的yapi包。我在Python2.7工作,它工作正常。

但是当我升级到Python 3.3时,它突然给了我一个证书错误。

输入

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

输出

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

我不得不改为Python 3.4来尝试支持我使用的其他只支持3及更高版本的功能。

1 个答案:

答案 0 :(得分:0)

尝试从

更改manager.py第47行
con = requests.get(req_url)

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

SSL证书可能存在问题。

可能与我使用requests库的issue有关。