![](/img/trans.png)
[英]Connecting to Atlas MongoDb using pymongo - ServerSelectionTimeoutError
[英]Problem connecting to mongodb atlas using python
我在連接到 Mongo 時遇到問題。 將不勝感激幫助..謝謝
client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')
db=client.get_database('dbImages')
records = db.atopic
records.count_documents({})
new_student = {
'name': 'ram',
'roll_no': 321,
'branch': 'it'
}
records.insert_one(new_student)
new_students = [
{
'name': 'alex',
'roll_no': 320,
'branch': 'it'
},
{
'name': 'john',
'roll_no': 30,
'branch': 'ece'
}
]
records.insert_many(new_students)
和錯誤:
Traceback (most recent call last):
File "C:/Users/student/Documents/GitHub/SRD/imageProcessing.py", line 24, in <module>
**client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')**
File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\mongo_client.py", line 672, in __init__
connect_timeout=timeout)
File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\uri_parser.py", line 453, in parse_uri
**'%s -m pip install "pymongo[srv]"' % (python_path))
pymongo.errors.ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra:
C:\Users\student\.windows-build-tools\python27\python.exe -m pip install "pymongo[srv]"**
你需要安裝 dnspython,試試這個命令來安裝它:
python -m pip install pymongo[srv]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.