Why is PyMongo 3 giving ServerSelectionTimeoutError?

后端 未结 20 954
我在风中等你
我在风中等你 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:02

    I encountered this too.

    This could be due to pymongo3 isn't fork safe.

    I fix this by adding --lazy-apps param to uwsgi, this can avoid the "fork safe" problem.

    seeing uwsgi doc preforking-vs-lazy-apps-vs-lazy.

    Notice, no sure for this two having positive connection.

    0 讨论(0)
  • 2020-11-30 02:02

    I was facing the same exception today. In my case, the proxy settings were probably blocking the connection since I could establish a successful connection to the mongodb by changing my wifi. Even if this question is marked as solved already, it can hopefully narrow down the problem for some others.

    0 讨论(0)
  • I commented out bindIP variable in mongod.conf instead of allowing all connections (for which you have to enter 0.0.0.0). Of course, beware of the consequence.

    0 讨论(0)
  • 2020-11-30 02:04

    The developers are investigating this problem, tracked in PYTHON-961. You may be able to work around the issue by running mongod.exe manually and monitoring it. This issue arises when the console freezes and you can hit the enter if the mongod console is got stuck. This is the simplest solution for now until the developers fix this bug.

    0 讨论(0)
  • 2020-11-30 02:04

    If it can help, I solved by replace :

    from flask.ext.mongoengine import MongoEngine
    

    by :

    from flask_mongoengine import MongoEngine
    
    0 讨论(0)
  • 2020-11-30 02:05

    We're investigating this problem, tracked in PYTHON-961. You may be able to work around the issue by passing connect=False when creating instances of MongoClient. That defers background connection until the first database operation is attempted, avoiding what I suspect is a race condition between spin up of MongoClient's monitor thread and multiprocess forking.

    0 讨论(0)
提交回复
热议问题