notes2notion icon indicating copy to clipboard operation
notes2notion copied to clipboard

SSL: CERTIFICATE_VERIFY_FAILED

Open fm1randa opened this issue 2 years ago • 7 comments

Expected Behavior

Run poetry run python main.py notes2notion.yaml successfully.

Current Behavior

The above command is returning an SSL error:

➜ poetry run python ./main.py ./notes2notion.yaml
Traceback (most recent call last):
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/backends/sync.py", line 62, in start_tls
    raise exc
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/backends/sync.py", line 57, in start_tls
    sock = ssl_context.wrap_socket(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create
    self.do_handshake()
  File "/usr/local/Cellar/[email protected]/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 218, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 253, in handle_request
    raise exc
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 237, in handle_request
    response = connection.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 86, in handle_request
    raise exc
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 63, in handle_request
    stream = self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 150, in _connect
    stream = stream.start_tls(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/backends/sync.py", line 54, in start_tls
    with map_exceptions(exc_map):
  File "/usr/local/Cellar/[email protected]/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/filipe.miranda/repos/personal/notes2notion/./main.py", line 26, in <module>
    archive = session.pages.retrieve(conf.import_page_id)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/notional/session.py", line 319, in retrieve
    data = self().retrieve(page_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/notion_client/api_endpoints.py", line 209, in retrieve
    return self.parent.request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/notion_client/client.py", line 189, in request
    response = self.client.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_client.py", line 908, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_client.py", line 936, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_client.py", line 973, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_client.py", line 1009, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 217, in handle_request
    with map_httpcore_exceptions():
  File "/usr/local/Cellar/[email protected]/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

Context (Environment)

macOS Monterey 12.6 Python 3.10.8 Dependencies installed and up-to-date.

fm1randa avatar Dec 06 '22 23:12 fm1randa

It looks like your local system is missing (or has out of date) SSL root certificates.

In the same folder, can you try running the following command:

poetry run pip install --upgrade certifi

And see if that changes the behavior? That will help pinpoint if the issue is in the Python environment or on the system.

jheddings avatar Dec 07 '22 00:12 jheddings

It returns:

Requirement already satisfied: certifi in /Users/filipe.miranda/Library/Caches/pypoetry/virtualenvs/notes2notion-255QKHSF-py3.11/lib/python3.11/site-packages (2022.9.24)

And behavior didn't change.

fm1randa avatar Dec 07 '22 00:12 fm1randa

This one has me stumped a bit. The error is coming from an out of date (or missing) SSL certificate on your system. It's not obvious where the missing cert is, but we can try to narrow down the issue a little bit.

Are you able to hit the API directly using cURL? Try the following command, but put your integration token in place of $NOTION_API_KEY (and be sure not to share that token here):

curl 'https://api.notion.com/v1/users/me' \
  -H "Authorization: Bearer $NOTION_API_KEY" \
  -H "Notion-Version: 2022-06-28"

That should return an object from the API, similar to the following:

{
  "object": "user",
  "id": "16d84278-ab0e-484c-9bdd-b35da3bd8905",
  "name": "pied piper",
  "avatar_url": null,
  "type": "bot",
  "bot": {
    ...
  }
}

jheddings avatar Dec 13 '22 17:12 jheddings

@fm1randa have you been able to gather any more information on this one? It seems to be working properly on other systems, so I will close out this issue for now unless there is more data to help debug it.

jheddings avatar Jan 27 '23 13:01 jheddings

I received this same error when trying to run the script when I was connected to company VPN. After disconnecting VPN the script ran fine. It's likely the VPN is causing an issue with the certs.

nwoolste avatar Feb 27 '23 15:02 nwoolste

I received this same error when trying to run the script when I was connected to company VPN. After disconnecting VPN the script ran fine. It's likely the VPN is causing an issue with the certs.

Ah, good data point! Do you have the same issue using cURL or other libraries when on the VPN?

jheddings avatar Feb 27 '23 16:02 jheddings

I did not have the same issue using the curl command while connected to vpn

nwoolste avatar Feb 27 '23 17:02 nwoolste

Closing this as "cannot reproduce" due to the company VPN. Please reopen with additional data if you have this issue in the future!

jheddings avatar May 31 '24 02:05 jheddings