omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    PyMongo ServerSelectionTimeoutError

    Pythonista
    3
    10
    4625
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Penguin Master
      Penguin Master last edited by

      Hi, I'm trying to use PyMongo and MongoDB with Pythonista 3, but I'm getting this error:

      pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: redacted-db-shard-00-02.loevh.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749),SSL handshake failed: redacted-db-shard-00-01.loevh.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749),SSL handshake failed: redacted-db-shard-00-00.loevh.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
      
      

      Ignore the redacteds, I just put those to hide the sensitive info. I know the URL is right, because I tested that exact connection URL on MongoDB (with the same code), so the issue is with Pythonista/iPadOS. Thanks in advance :)

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        https://forum.omz-software.com/topic/6751/pymongo-errors-configurationerror-resolver-configuration-could-not-be-read-or-specified-no-nameservers

        Penguin Master 1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          Since you are getting a certificate failure, you might try the pep 473 approach to monkeypatch ssl to not verifying certificates:

          import ssl
          
          try:
              _create_unverified_https_context = ssl._create_unverified_context
          except AttributeError:
              # Legacy Python that doesn't verify HTTPS certificates by default
              pass
          else:
              # Handle target environment that doesn't support HTTPS verification
              ssl._create_default_https_context = _create_unverified_https_context
          

          If that works, then the issue is probably that the certificate is wrong (hostname doesn't match cert, etc) or not signed by a trusted CA. There may be ways to install the certificate locally in that case.

          1 Reply Last reply Reply Quote 0
          • Penguin Master
            Penguin Master @ccc last edited by

            @ccc Thanks, but that's not the same error and besides, I'm already using dns.resolver

            1 Reply Last reply Reply Quote 1
            • Penguin Master
              Penguin Master last edited by

              @JonB Update: that sadly didn't fix it. I'm getting the exact same error still. Are there any other possible solutions? Thanks

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                You could try pip install certifi.

                Is this your own server? Take a look at the certificate, and check if the signing authority is trusted... Or install the certificate in the trust store (maybe editing certifi's cacerts.pem)

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  See https://stackoverflow.com/questions/54484890/ssl-handshake-issue-with-pymongo-on-python3

                  There are a few options in that thread. One uses ssl_cert_reqs=ssl.CERT_NONE. the other uses ca=certifi.where(), and tlsCAFile=ca.

                  1 Reply Last reply Reply Quote 0
                  • Penguin Master
                    Penguin Master last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • Penguin Master
                      Penguin Master last edited by

                      @JonB thank you so much! It's working perfectly again :)

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        For reference, which solution worked?

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors