ServerSelectionTimeoutError Pymongo

夙愿已清 提交于 2020-03-26 04:19:22

问题


I'm trying out pymongo for the first time and I keep getting a ServerSelectionTimeoutError. When using mongo commandline to login I run a command as follows

$ 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.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()

回答1:


Your connection string is missing the options that your shell command line provides, namely ssl and option to allow invalid certificate.

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)



来源:https://stackoverflow.com/questions/54064725/serverselectiontimeouterror-pymongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!