简体   繁体   English

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] 连接拒绝 django 到 heroku

[英]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.

相关问题 pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] 连接被拒绝 - pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused Mongodb pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection denied, Timeout: 30s, - Mongodb pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, pymongo.errors.ServerSelectionTimeoutError:本地主机:27017:[Errno 61]连接被拒绝 - pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused 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 连接到 mongo 图集给出 pymongo.errors.ServerSelectionTimeoutError: localhost:27017 - Connecting to mongo atlas gives pymongo.errors.ServerSelectionTimeoutError: localhost:27017 pymongo.errors.ServerSelectionTimeoutError - pymongo.errors.ServerSelectionTimeoutError 在连接到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 烧瓶 - pymongo.errors.ServerSelectionTimeoutError - Flask - pymongo.errors.ServerSelectionTimeoutError pymongo.errors.ServerSelectionTimeoutError:db:27017:超时,超时:30s, - pymongo.errors.ServerSelectionTimeoutError: db:27017: timed out, Timeout: 30s, pymongo.errors.ServerSelectionTimeoutError: RepliceSetNoPrimary - MongoDB Atlas - pymongo.errors.ServerSelectionTimeoutError: RepliceSetNoPrimary - MongoDB Atlas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM