[英]pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused django to heroku
I'm using django with mongodb atlas and trying to deploy using heroku.我正在将 django 与 mongodb atlas 一起使用,并尝试使用 heroku 进行部署。 Somehow I keep facing pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
this error.不知何故,我一直面临pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
此错误。
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'name',
'HOST': 'mongodb+srv://user:pass@cluster0-xb9zh.mongodb.net/test?retryWrites=true&w=majority',
'USER': 'user',
'PASSWORD': 'pass',
}
}
For django setting.py I simply changed it from sqlite
to mongodb.对于 django setting.py,我只是将它从sqlite
更改为 mongodb。 It works perfectly in my local.它在我的本地工作得很好。 There is one change I am suspicious is I had to change a mongo_client.py
file from localhost to the connection string in order to make my mongodb connect to atlas instead of my local database.我怀疑的一个变化是我必须将mongo_client.py
文件从 localhost 更改为连接字符串,以便让我的 mongodb 连接到 atlas 而不是我的本地数据库。 Not sure if that has anything to do with this.不确定这是否与此有关。
class MongoClient(common.BaseObject):
"""
A client-side representation of a MongoDB cluster.
Instances can represent either a standalone MongoDB server, a replica
set, or a sharded cluster. Instances of this class are responsible for
maintaining up-to-date state of the cluster, and possibly cache
resources related to this, including background threads for monitoring,
and connection pools.
"""
HOST = "mongodb+srv://user:pass@cluster0-xb9zh.mongodb.net/test?retryWrites=true&w=majority"
PORT = 27017
# Define order to retrieve options from ClientOptions for __repr__.
This error usually arises when you haven't white listed the IP your client is running on.当您没有将客户端运行的 IP 列入白名单时,通常会出现此错误。 See the details here:在此处查看详细信息:
https://docs.atlas.mongodb.com/security-whitelist/ https://docs.atlas.mongodb.com/security-whitelist/
Do not know if this helps much, but you could also this不知道这是否有帮助,但你也可以这样做
DATABASES = {
'default': {
'ENGINE': 'djongo',
'CLIENT': {
'host': 'mongodb+srv://<URL>',
'username': 'something',
'password': 'somepass',
'authMechanism': 'SCRAM-SHA-1'
}
}
}
It helped me, but for u it might not be the case.它帮助了我,但对你来说可能并非如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.