pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed

It may be due to the OpenSSL updates. If you are on ubuntu:22.04, upgrade to ubuntu:23.x. However what OS are you on right now and the mongodb version now?