pymongo 3.4.0 连接到 mongo 图集
pymongo 3.4.0 connecting to mongo atlas
我有python2.7,有pymongo3.4
我正在尝试使用以下方法连接到 mongo atlas :
import certifi
import ssl
import os
from pymongo import MongoClient
MongoClient(
"mongodb://Admin:<PASSWORD>@ABC-shard-00-00-XYZ:27017",
"ABC-shard-00-01-XYZ:27017",
"ABC-shard-00-02-XYZ:27017/dev?ssl=true&replicaSet=ABC-0&authSource=admin",
ssl_cert_reqs=ssl.CERT_REQUIRED,
ssl_ca_certs=certifi.where()
)
它一直失败,身份验证失败。代码 18
如Using PyMongo with MongoDB Atlas所述:
从 PyMongo v3.4.0, you can connect to MongoDB Atlas by passing the Connection String URI provided by MongoDB Atlas to MongoClient 开始,示例:
from pymongo import MongoClient
client = MongoClient("mongodb://USER:PASSWORD@ABC-cluster-shard-00-00-XYZ.mongodb.net:27017,ABC-cluster-shard-00-01-XYZ.mongodb.net:27017,ABC-cluster-shard-00-02-XYZ.mongodb.net:27017/DATABASE?ssl=true&replicaSet=ABC-cluster-shard-0&authSource=admin")
连接到 MongoDB Atlas 需要 TLS/SSL. With PyMongo 3.3+, you can install PyMongo 3.3+ and any TLS/SSL-related dependencies using the following Python pip 命令:
python -m pip install pymongo[tls]
我有python2.7,有pymongo3.4
我正在尝试使用以下方法连接到 mongo atlas :
import certifi
import ssl
import os
from pymongo import MongoClient
MongoClient(
"mongodb://Admin:<PASSWORD>@ABC-shard-00-00-XYZ:27017",
"ABC-shard-00-01-XYZ:27017",
"ABC-shard-00-02-XYZ:27017/dev?ssl=true&replicaSet=ABC-0&authSource=admin",
ssl_cert_reqs=ssl.CERT_REQUIRED,
ssl_ca_certs=certifi.where()
)
它一直失败,身份验证失败。代码 18
如Using PyMongo with MongoDB Atlas所述:
从 PyMongo v3.4.0, you can connect to MongoDB Atlas by passing the Connection String URI provided by MongoDB Atlas to MongoClient 开始,示例:
from pymongo import MongoClient
client = MongoClient("mongodb://USER:PASSWORD@ABC-cluster-shard-00-00-XYZ.mongodb.net:27017,ABC-cluster-shard-00-01-XYZ.mongodb.net:27017,ABC-cluster-shard-00-02-XYZ.mongodb.net:27017/DATABASE?ssl=true&replicaSet=ABC-cluster-shard-0&authSource=admin")
连接到 MongoDB Atlas 需要 TLS/SSL. With PyMongo 3.3+, you can install PyMongo 3.3+ and any TLS/SSL-related dependencies using the following Python pip 命令:
python -m pip install pymongo[tls]