简体   繁体   English

Pymongo 与 MongoDB 图集的连接 - 错误 111 连接被拒绝

[英]Pymongo Connection with MongoDB atlas - Error 111 Connection refused

I'm setting up a cron job, where it fetches some data from MongoDB atlas in Python3 through Pymongo in Cpanel.我正在设置一个 cron 作业,它通过 Cpanel 中的 Pymongo 从 Python3 中的 MongoDB atlas 获取一些数据。 I always get a Error 111 Connnection refused.我总是收到错误 111 连接被拒绝。

I using python3.6 and pymongo-3.9.0, Cloud MongoDB-4.0.2我使用 python3.6 和 pymongo-3.9.0,Cloud MongoDB-4.0.2

I have tried via SSHtunnel forwarder, but not sure how to give host_ip_addres, where MongoDB is in cluster我已经尝试通过 SSHtunnel 转发器,但不确定如何提供 host_ip_addres,其中 MongoDB 在集群中

class DbConnection():
    def __init__(self):
        self.connectionServer = "mongodb+srv://"
        self.userName = "name"
        self.userPass = "pass"
        self.connectionCluster = "@temp-cluster0-lt2rb.mongodb.net"
        self.connectionDb = "developmentDB"

    def db_connect(self):
        ''' This function is used to connect to remote db with authentication
            Return type --> returns the url string of the db
            parameters--> self
            '''
        try:
            connectionUrl = self.connectionServer + self.userName + ":" + self.userPass + self.connectionCluster + "/test?retryWrites=true&w=majority"
            print(connectionUrl)
            myClient = pymongo.MongoClient(connectionUrl, port=12312)
            db = myClient.test
            print(myClient.test)

I'm expecting it to connect to the MongoDB cluster DB and read/Write the documents through it.我期待它连接到 MongoDB 集群数据库并通过它读取/写入文档。

So the comments for the question solved the issue, so i'll just put this here for any future reference所以问题的评论解决了这个问题,所以我把它放在这里以供将来参考

The error can be resulted for must people because of a miss-configuration when moving from a self hosted MongoDB to a Remoted host service (Like MongoDB Atlas)由于从自托管 MongoDB 移动到远程主机服务(如 MongoDB Atlas)时配置错误,必须人员可能会出现该错误

So, the +srv is DNS Seed List Connection Format .所以, +srvDNS Seed List Connection Format

When switching from port based connection to DNS seed based connection, we should remove any port configuration from our connection string, ie:从基于端口的连接切换到基于 DNS 种子的连接时,我们应该从连接字符串中删除任何端口配置,即:

class DbConnection():
    def __init__(self):
        self.connectionServer = "mongodb+srv://"
        self.userName = "name"
        self.userPass = "pass"
        self.connectionCluster = "@temp-cluster0-lt2rb.mongodb.net"
        self.connectionDb = "developmentDB"

    def db_connect(self):
        ''' This function is used to connect to remote db with authentication
            Return type --> returns the url string of the db
            parameters--> self
            '''
        try:
            connectionUrl = self.connectionServer + self.userName + ":" + self.userPass + self.connectionCluster + "/test?retryWrites=true&w=majority"
            print(connectionUrl)
            // myClient = pymongo.MongoClient(connectionUrl, port=12312)
            // We remove the PORT 
            myClient = pymongo.MongoClient(connectionUrl)
            db = myClient.test
            print(myClient.test)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在连接到Heroku上的mongoDB时出现错误:“ localhost:27017:[Errno 111]连接被拒绝”,但在我的计算机上工作正常 - Getting error: “localhost:27017: [Errno 111] Connection refused” while connecting to mongoDB on Heroku but works fine on my computer Mysql([Errno 111] 连接被拒绝)”) - Mysql ([Errno 111] Connection refused)") Python 套接字收到错误“连接被拒绝错误 111” - Python socket getting the error “connection refused error 111” Errno111 连接被拒绝 Kivy 套接字错误 - Errno111 Connection Refused Kivy Socket Error urlopen错误[Errno 111]连接拒绝了selenium python - urlopen error [Errno 111] Connection refused for selenium python Docker。 无法建立新连接:[Errno 111] Connection refused' - Docker. Failed to establish a new connection: [Errno 111] Connection refused' python-valve rcon minecraft'ConnectionRefusedError:[Errno 111]连接被拒绝' - python-valve rcon minecraft 'ConnectionRefusedError: [Errno 111] Connection refused' PythonAnywhere ConnectionRefusedError:[Errno 111] 与 Twilio 一起使用时连接被拒绝 - PythonAnywhere ConnectionRefusedError: [Errno 111] Connection refused when used with Twilio Ftplib ConnectionRefusedError: [Errno 111] 连接被拒绝 (python 3.5) - Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5) 连接到SAP HANA:ConnectionRefusedError:[Errno 111]连接被拒绝 - connecting to SAP HANA : ConnectionRefusedError: [Errno 111] Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM