Chapter 0: "pytest -m connection" and "python run.py" failing (SSL handshake failed)

Hi,
I’m trying to get the “connection” test to run and it returns this error:
pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: mflix-shard-00-00.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],SSL handshake failed: mflix-shard-00-01.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],SSL handshake failed: mflix-shard-00-02.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')], Timeout: 30s, Topology Description: <TopologyDescription id: 62cddd7c848521e76373564a, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('mflix-shard-00-00.mt1jv.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect("SSL handshake failed: mflix-shard-00-00.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]")>, <ServerDescription ('mflix-shard-00-01.mt1jv.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect("SSL handshake failed: mflix-shard-00-01.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]")>, <ServerDescription ('mflix-shard-00-02.mt1jv.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect("SSL handshake failed: mflix-shard-00-02.mt1jv.mongodb.net:27017: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]")>]>

This is the address in my .ini file:
mongodb+srv://m220student:m220password@mflix.mt1jv.mongodb.net/?retryWrites=true&w=majority

While python doesn’t reach the DB, it works fine if I connect with the mongo shell with the following connection string:
mongosh "mongodb+srv://mflix.mt1jv.mongodb.net/myFirstDatabase" --apiVersion 1 --username m220student --password m220password

This is my current setup:

  • OS: Windows 10 21H2 64 bit
  • Python: Python 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
  • MongoDB: 5.0.9 (API Version 1)

What could be wrong? I’ve tried every answer given for this topic but still doesn’t work after 2 days. Any help would be much appreciated.

Regards,
Marco

same her , but nobody replying.

Hi, are you still getting the error?

pytest -m connection works for me without any error using this .ini file:

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.mt1jv.mongodb.net/?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix.mt1jv.mongodb.net/?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

OS: Ubuntu 18.04
Python: 3.7.6
MongoDB: 5.0.9

  • Most likely: you should fill in both MFLIX_DB_URI variables in .ini
  • Maybe: there was a problem with SSL certificates on mongoDB Atlas side and they have fixed it in the meantime.
  • Maybe: python 3.9 is too high?
  • Maybe: don’t forget to whitelist your IP address!

Brother I did everything as mentioned in assignment, but failed. not a single solution is given. they must have given a video. mY python is 3.7 with windows 10. There is no option of IP whitelist in network section

pymongo.errors.ServerSelectionTimeoutError: ac-ldxh4t9-shard-00-02.bob34dy.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1091),ac-ldxh4t9-shard-00-01.bob34dy.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1091),ac-ldxh4t9-shard-00-00.bob34dy.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1091)

Yes tried it but did not work.

[SSL: CERTIFICATE_VERIFY_FAILED]

To whitelist IP do the following:

  1. Go to Atlas https://cloud.mongodb.com .
  2. Find “Network Access” bottom left.
  3. Add IP address 0.0.0.0/0 if it’s not there clicking “+ ADD IP ADDRESS” top right.

There is an option IP access list which I have already done yesterday. still not working.
SSL certifiacte exoire msg.

[SSL: CERTIFICATE_VERIFY_FAILED]: certificate has expired on Mongo Atlas]
Sir,
problem is solved.
Via this solution ----->

Thank You

2 Likes