代碼
client = pymongo.MongoClient("mongodb srv://username:[email protected]/db?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE")
db = client["db"]
#this gives the error
res = list(db.listings.find({}).limit(15).sort([('$natural',-1)]))
錯誤:
pymongo.errors.ServerSelectionTimeoutError: No replica set members found yet
我在分配變數的行中收到此錯誤res。在我的機器上運行它時我沒有得到這個錯誤,但是當我在服務器上運行它時我得到了錯誤。
uj5u.com熱心網友回復:
這種型別的錯誤通常是:
- 未使用最新
pymongo驅動程式(https://pypi.org/project/pymongo/列出當前最新版本) - 沒有
dnspython安裝模塊(我有問題 2.1.0 所以會推薦 2.0.0)
uj5u.com熱心網友回復:
我嘗試了這些答案中的所有解決方案,但唯一有效的方法就是使用flask_pymongo模塊而不是pymongo. 現在我沒有收到任何錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/344965.html
