requests-html icon indicating copy to clipboard operation
requests-html copied to clipboard

"certificate verify failed" when downloading Chromium on macOS

Open antonkravc opened this issue 8 years ago • 5 comments

Just started experimenting with the library and encountered an error. I am running Python 3.6.4 on macOS High Sierra (10.13.3).

I have tried to execute the following code:

from requests_html import HTMLSession

session = HTMLSession()

r = session.get('https://python.org')
r.html.render()

And I get the following error as a result.

[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/anton/Development/Local/Drafts/scraping.py", line 6, in <module>
    r.html.render()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_html.py", line 416, in render
    content, result = loop.run_until_complete(_async_render(url=self.url, script=script, sleep=sleep, wait=wait, content=self.html, reload=reload, scrolldown=scrolldown, timeout=timeout))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_html.py", line 373, in _async_render
    browser = pyppeteer.launch(headless=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyppeteer/launcher.py", line 161, in launch
    return Launcher(options, **kwargs).launch()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyppeteer/launcher.py", line 87, in __init__
    download_chromium()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyppeteer/chromium_downloader.py", line 94, in download_chromium
    extract_zip(download_zip(get_url()), DOWNLOADS_FOLDER / REVISION)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyppeteer/chromium_downloader.py", line 58, in download_zip
    with request.urlopen(url) as f:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

antonkravc avatar Mar 02 '18 09:03 antonkravc

Ok, apparently this is a macOS related issue and is not related to the library. Just in case anyone else runs into this problem, the solution is described here and the bug itself is described here.

antonkravc avatar Mar 02 '18 11:03 antonkravc

Hi, I've just run into the same problem on Windows 8, Python 3.7. PIP works fine, I'm getting the error only when requests-html tries to download Chromium. My certifi package is up to date. Any idea how to fix/bypass this issue?

MKaras93 avatar May 24 '19 10:05 MKaras93

https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/42334357#42334357

l3n641 avatar Jun 02 '19 03:06 l3n641

Suffering from the same issue here, both on installs from a regular MacOS Python venv, as well on miniconda binaries. I've tried to use the solution that @l3n641 described, but I'm not able to find an Install Certificates.command. Any hints on how to solve that?

ricardobarroslourenco avatar Feb 03 '20 19:02 ricardobarroslourenco

Suffering from the same issue here, both on installs from a regular MacOS Python venv, as well on miniconda binaries. I've tried to use the solution that @l3n641 described, but I'm not able to find an Install Certificates.command. Any hints on how to solve that?

I ran into this exact error. My copy of python3 was installed via brew, which did not come with the Install Certificates.command. I solved this problem by going to the following website: https://github.com/miyakogi/pyppeteer. Make sure the pyppeteer package is installed, and then run the first sample code on the website. The code will download a copy of the chromium.

Then this problem in requests-html disappeared.

YuMan-Tam avatar Apr 23 '20 04:04 YuMan-Tam