Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1054

Database connection timeout error

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Done
    • None
    • None
    • None
    • None
    • Microsoft Windows [Version 6.3.9600]; 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Dec 18 2014, 16:57:52) [MSC v.1500 64 bit (AMD64)]

    Description

      After doing a search, I've seen this issue however, they're much more complicated cases. I'm sticking with the basics going through the tutorial and having the same timeout error. In those posts, they suggest using connect=False when using MongoClient but that doesn't seem to help.

      Thanks for your time!

      Code below:
      import pymongo;
      from pymongo import MongoClient;
      import datetime;

      1. Please note that for privacy, I have changed these values. The real values do work from mongo. #
        client = MongoClient(
        host='example.com',
        connect=False,
        ssl=True,
        ssl_keyfile='key.pem',
        ssl_ca_certs='ca.pem'
        );

      db = client.test_database;

      post =

      {"author": "Mike", "text": "My first blog post!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow() }

      ;

      posts = db.posts;

      post_id = posts.insert_one(post).inserted_id;

      ########################
      The error is below:

      Traceback (most recent call last):
      File "MONGO_CONNECT_ONLY.py", line 26, in <module>
      post_id = posts.insert_one(post).inserted_id;
      File "C:\Anaconda\lib\site-packages\pymongo\collection.py", line 622, in insert_one with self._socket_for_writes() as sock_info:
      File "C:\Anaconda\lib\contextlib.py", line 17, in _enter_
      return self.gen.next()
      File "C:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 712, in _get_socket
      server = self._get_topology().select_server(selector)
      File "C:\Anaconda\lib\site-packages\pymongo\topology.py", line 141, in select_
      server
      address))
      File "C:\Anaconda\lib\site-packages\pymongo\topology.py", line 117, in select_
      servers
      self._error_message(selector))
      pymongo.errors.ServerSelectionTimeoutError: connection closed

      Attachments

        Activity

          People

            bernie@mongodb.com Bernie Hackett
            need.pymongo.help Need Py Mongo Help
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: