Why is PyMongo 3 giving ServerSelectionTimeoutError?

后端 未结 20 1102
我在风中等你
我在风中等你 2020-11-30 01:21

I\'m using:

  • Python 3.4.2
  • PyMongo 3.0.2
  • mongolab running mongod 2.6.9
  • uWSGI 2.0.10
  • CherryPy 3.7.0
  • nginx 1.6.2
20条回答
  •  孤城傲影
    2020-11-30 02:18

    pymongo 3 will not tell you your connection failed when you instantiate your client. You may not be connected.

    https://api.mongodb.com/python/3.5.1/api/pymongo/mongo_client.html

    "it no longer raises ConnectionFailure if they are unavailable .. You can check if the server is available like this:"

    from pymongo.errors import ConnectionFailure
    client = MongoClient()
    try:
        # The ismaster command is cheap and does not 
    require auth.
        client.admin.command('ismaster')
    except ConnectionFailure:
        print("Server not available")
    

提交回复
热议问题