[英]ServerSelectionTimeoutError Pymongo
I'm trying out pymongo for the first time and I keep getting a ServerSelectionTimeoutError.我是第一次尝试 pymongo,但一直收到 ServerSelectionTimeoutError。 When using mongo commandline to login I run a command as follows
使用 mongo 命令行登录时,我运行如下命令
$ mongo-3.0 --ssl test.net:27080/db_qa --sslAllowInvalidCertificates -u content -p
MongoDB shell version: 3.0.12
Enter password:
and I'm able to connect fine but with pymongo I get the error我可以正常连接,但是使用 pymongo 时出现错误
pymongo.errors.ServerSelectionTimeoutError: test.net:27080: [Errno 60] Operation timed out
My code is as follows我的代码如下
from pymongo import MongoClient
client = MongoClient('mongodb://content:<password>@test.net:27080/db_qa')
client.server_info()
Your connection string is missing the options that your shell command line provides, namely ssl
and option to allow invalid certificate.您的连接字符串缺少 shell 命令行提供的选项,即
ssl
和允许无效证书的选项。
You could add ?ssl=true&ssl_cert_reqs=CERT_NONE
after the database name in the string you are passing to MongoClient
or see other options for certificate handling on MongoClient page (scroll to "SSL configuration" section)您可以在传递给
MongoClient
的字符串中的数据库名称之后添加?ssl=true&ssl_cert_reqs=CERT_NONE
或在MongoClient页面上查看证书处理的其他选项(滚动到“SSL 配置”部分)
因此,对我有用的是我刷新了在“设置连接安全性”选项卡下更改的当前 IP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.