所以我在 AWS 上創建了一個 documentDB 集群,并將它托管在一個 EC2 實體上。它們都在同一個 VPC 中。
在 EC2 實體中,我可以使用 shell 通過 shell 連接到它
mongo --ssl --host <Hostname> --sslCAFile rds-combined-ca-bundle.pem --username <Username>--password <insertYourPassword>
但是當我嘗試運行我的 python 檔案進行連接時,它會給我一個警告
/home/ubuntu/.local/lib/python3.8/site-packages/pymongo/common.py:787: UserWarning: Unknown option ssl_ca_certs
warnings.warn(str(exc))
之后我得到一個錯誤
pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: <Hostname>: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')], Timeout: 30s, Topology Description: <TopologyDescription id: 62520d257a1153e03b78ec0b, topology_type: Unknown, servers: [<ServerDescription ('<Hostname>', 27017) server_type: Unknown, rtt: None, error=AutoReconnect("SSL handshake failed: <Hostname>: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]")>]>
這是僅用于 conntest.py 的代碼
url = 'mongodb://<Username>:<insertYourPassword>@<host>/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&retryWrites=false'
client = pymongo.MongoClient(url)
##Specify the database to be used
db = client.sample_database
##Specify the collection to be used
col = db.sample_collection
##Insert a single document
col.insert_one({'hello':'Amazon DocumentDB'})
##Find the document that was previously written
x = col.find_one({'hello':'Amazon DocumentDB'})
##Print the result to the screen
print(x)
##Close the connection
client.close()
引陣列是默認的,除了 tls : disabled ttl_monitor : disabled
.pem 檔案本地保存在與 python 代碼相同的檔案夾中
uj5u.com熱心網友回復:
您的 URL 字串錯誤。你需要類似的東西:
url = 'mongodb://<Username>:<insertYourPassword>@<host>/?ssl=true&tlsCertificateKeyFile=rds-combined-ca-bundle.pem&retryWrites=false'
我不確定你從哪里得到的ssl_ca_certs引數。所有 URL 引數都記錄在這里。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/457943.html
標籤:Python mongodb 亚马逊网络服务 亚马逊-ec2 aws-documentdb
上一篇:Mongodb:陣列中的多個物件
