Certificate_verify_failed m220p

I’m still getting the similar error after trying the suggestions provided above.

(mflix) D:\MongoDB\mflix-python>pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.6.5, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: D:\MongoDB\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0, remotedata-0.2.1, openfiles-0.3.0, doctestplus-0.1.3, arraydiff-0.2
collected 43 items

tests\test_db_connection.py FFFF [100%]

================================== FAILURES ===================================
______________________________ test_atlas_setup _______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>
config = <Config {‘DEBUG’: False, ‘TESTING’: False, ‘PROPAGATE_EXCEPTIONS’: True, ‘PRESERVE_CONTEXT_ON_EXCEPTION’: None, 'SECRE…8>, ‘MFLIX_NS’: ‘sample_mflix’, ‘MFLIX_DB_URI’: ‘mongodb+srv://m220student:m220password@mflix.znz1w.mongodb.net/test’}>

@pytest.mark.connection
@pytest.mark.usefixtures('config')
def test_atlas_setup(client, config):
  result = get_coll_names(config)

tests\test_db_connection.py:24:


tests\test_db_connection.py:18: in get_coll_names
return db.list_collection_names()
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\database.py:863: in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\database.py:826: in list_collections
_cmd, read_pref, session)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1461: in _retryable_read
read_pref, session, address=address)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1278: in _select_server
server = topology.select_server(server_selector)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:243: in select_server
address))
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:200: in select_servers
selector, server_timeout, address)


self = <Topology <TopologyDescription id: 60ec3d7e9bd8d8521eb1074f, topology_type: ReplicaSetNoPrimary, servers: [<ServerDesc…lix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address, custom_selector=self._settings.server_selector)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
                "%s, Timeout: %ss, Topology Description: %r" %
              (self._error_message(selector), timeout, self.description))

E pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833), Timeout: 30s, Topology Description: <TopologyDescription id: 60ec3d7e9bd8d8521eb1074f, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘mflix-shard-00-00.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-01.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-02.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:217: ServerSelectionTimeoutError
______________________________ test_basic_movies ______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_basic_movies(client):
  (actual, num_found) = get_movies({}, 0, 20)

tests\test_db_connection.py:31:


mflix\db.py:224: in get_movies
total_num_movies = db.movies.count_documents(query)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py:1786: in count_documents
_cmd, self._read_preference_for(session), session)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1461: in _retryable_read
read_pref, session, address=address)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1278: in _select_server
server = topology.select_server(server_selector)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:243: in select_server
address))
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:200: in select_servers
selector, server_timeout, address)


self = <Topology <TopologyDescription id: 60ec3d9d9bd8d8521eb10750, topology_type: ReplicaSetNoPrimary, servers: [<ServerDesc…lix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address, custom_selector=self._settings.server_selector)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
                "%s, Timeout: %ss, Topology Description: %r" %
              (self._error_message(selector), timeout, self.description))

E pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833), Timeout: 30s, Topology Description: <TopologyDescription id: 60ec3d9d9bd8d8521eb10750, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘mflix-shard-00-00.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-01.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-02.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:217: ServerSelectionTimeoutError
___________________________ test_search_by_movie_id ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_search_by_movie_id(client):
    actual = get_movie("573a13acf29313caabd29647")
  assert actual['title'] == 'King Kong'

E KeyError: ‘title’

tests\test_db_connection.py:39: KeyError
___________________________ test_simple_text_search ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_simple_text_search(client):
  (actual, _) = get_movies({"$text": {"$search": "King Kong"}}, 0, 20)

tests\test_db_connection.py:44:


mflix\db.py:224: in get_movies
total_num_movies = db.movies.count_documents(query)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py:1786: in count_documents
_cmd, self._read_preference_for(session), session)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1461: in _retryable_read
read_pref, session, address=address)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1278: in _select_server
server = topology.select_server(server_selector)
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:243: in select_server
address))
C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:200: in select_servers
selector, server_timeout, address)


self = <Topology <TopologyDescription id: 60ec3dda9bd8d8521eb10752, topology_type: ReplicaSetNoPrimary, servers: [<ServerDesc…lix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address, custom_selector=self._settings.server_selector)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
                "%s, Timeout: %ss, Topology Description: %r" %
              (self._error_message(selector), timeout, self.description))

E pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833),SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833), Timeout: 30s, Topology Description: <TopologyDescription id: 60ec3dda9bd8d8521eb10752, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘mflix-shard-00-00.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-00.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-01.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-01.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>, <ServerDescription (‘mflix-shard-00-02.znz1w.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘SSL handshake failed: mflix-shard-00-02.znz1w.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’,)>]>

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py:217: ServerSelectionTimeoutError
============================= 39 tests deselected =============================
================== 4 failed, 39 deselected in 124.33 seconds ==================

Hi @Vaibhav_Jain1

I’ve moved this to a new issue to ensure we address your issue and not the older issue in the former thread. Please start a new thread when creating a question or outlining a problem as it helps to ensure the focus remains specifically on your problem/question.

This looks familiar, PyMongo requires dnspython>=1.16<2. Please install+upgrade pymongo with the srv extra like this:

python -m pip install --upgrade 'pymongo[srv]'

See: https://pymongo.readthedocs.io/en/stable/installation.html#dependencies

If this doesn’t resolve your issue, you should review this thread ([M220] Connection issue trying to connect with mongo shell: (SSL CERTIFICATE_VERIFY_FAILED) - #8 by Eoin_Brazil) and see if there is any further suggestions in that thread that can assist your issue.

Kindest regards,
Eoin

1 Like

Thanks @Eoin_Brazil . I was able to fix the issue after using certifi.where() as mentioned in the chat link you provided. Many thanks!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.