简体   繁体   English

Mongodb pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection denied, Timeout: 30s,

[英]Mongodb pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s,

I am trying to locally connect to my db.我正在尝试本地连接到我的数据库。 I've established a connection to the database on MongoDB Compass, but when I run my simple code, I get this error:我已经在 MongoDB Compass 上建立了与数据库的连接,但是当我运行我的简单代码时,我收到了这个错误:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 60e2b31fab1da2bb146bb38c, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]> root@LAPTOP-8OKVP35I:/portfolio/myProjects/webDevelopment/shopify_db# pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection denied, Timeout: 30s, Topology Description: <TopologyDescription id: 60e2b31fab1da2bb146bb38c, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt:无,error=AutoReconnect('localhost:27017: [Errno 111] Connection denied')>]> root@LAPTOP-8OKVP35I:/portfolio/myProjects/webDevelopment/shopify_db#

This is the code I am running:这是我正在运行的代码:

import pymongo
from pymongo import MongoClient

client = pymongo.MongoClient()
db = client["Shopper_Info"]
my_collection = db["Names"]
shopper_data = {'name': 'Yoni', 'email': 'test@gmail.com'}

my_collection.insert_one(shopper_data)

results= collection.find({"name": 'Yoni'})

for result in results:
print(result)

This problem was also happening in my stack, I had my connection string in an env file to connect to mongo atlas.这个问题也发生在我的堆栈中,我将连接字符串放在一个 env 文件中以连接到 mongo atlas。

MONGO_URI=mongodb://<username>:<password>@cluster-details

This happend to me as well.这也发生在我身上。 make sure that you have started the mongod server.that worked for me.确保您已经启动了对我有用的 mongod 服务器。

sudo service mongod start.

just add the above code to your settings.py in django:-只需将上述代码添加到 django 中的 settings.py 中:-

DATABASE = {
'default': {
'ENGINE': 'djongo',
 "CLIENT": {
           "name": <your_database_name>,
           "host": <your_connection_string>,
           "username": <your_database_username>,
           "password": <your_database_password>,
           "authMechanism": "SCRAM-SHA-1",
        },
    }
}

but in host you may get this issue:-"pymongo.errors.ServerSelectionTimeoutError:"[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997) so for this you add like:- "mongodb+srv://sampleUser:samplePassword@cluster0-gbdot.mongodb.net/sampleDB??ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority"但在主机中,您可能会遇到此问题:-“pymongo.errors.ServerSelectionTimeoutError:”[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书(_ssl.c:997)所以为此您添加如下:-“mongodb +srv://sampleUser:samplePassword@cluster0-gbdot.mongodb.net/sampleDB??ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority"

暂无
暂无

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

相关问题 pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] 连接被拒绝 - pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] 连接拒绝 django 到 heroku - pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused django to heroku pymongo.errors.ServerSelectionTimeoutError:本地主机:27017:[Errno 61]连接被拒绝 - pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused pymongo.errors.ServerSelectionTimeoutError:db:27017:超时,超时:30s, - pymongo.errors.ServerSelectionTimeoutError: db:27017: timed out, Timeout: 30s, pymongo pymongo.errors.ServerSelectionTimeoutError:hour must be in 0..23, Timeout: 30s, Topology Description: - pymongo pymongo.errors.ServerSelectionTimeoutError:hour must be in 0..23, Timeout: 30s, Topology Description: pymongo.errors.ServerSelectionTimeoutError:localhost:27017:[WinError 10061]无法建立连接,因为目标机器主动拒绝 - pymongo.errors.ServerSelectionTimeoutError:localhost:27017:[WinError 10061]No connection could be made because the target machine actively refused it Python pymongo 不断拒绝 [Errno111] Connection denied, Timeout: 30s - Python pymongo keeps refusing [Errno111] Connection refused, Timeout: 30s 连接到 mongo 图集给出 pymongo.errors.ServerSelectionTimeoutError: localhost:27017 - Connecting to mongo atlas gives pymongo.errors.ServerSelectionTimeoutError: localhost:27017 pymongo.errors.ServerSelectionTimeoutError: RepliceSetNoPrimary - MongoDB Atlas - pymongo.errors.ServerSelectionTimeoutError: RepliceSetNoPrimary - MongoDB Atlas pymongo.errors.ServerSelectionTimeoutError - pymongo.errors.ServerSelectionTimeoutError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM