尝试使用pymong时连接被拒绝

2024-04-18 01:47:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的瓶子里安装了pymongo。我试图使用它,但出现以下错误:

connection = Connection()
---------------------------------------------------------------------------
ConnectionFailure                         Traceback (most recent call last)
<ipython-input-9-609d5cb538f5> in <module>()
----> 1 connection = Connection()

/home/python/BENV/local/lib/python2.7/site-packages/pymongo/connection.pyc in __init__(self, host, port, max_pool_size, network_timeout, document_class, tz_aware, _connect, **kwargs)
    234 
    235         super(Connection, self).__init__(host, port,
--> 236                 max_pool_size, document_class, tz_aware, _connect, **kwargs)
    237 
    238     def __repr__(self):

/home/python/BENV/local/lib/python2.7/site-packages/pymongo/mongo_client.pyc in __init__(self, host, port, max_pool_size, document_class, tz_aware, _connect, **kwargs)
    367             except AutoReconnect, e:
    368                 # ConnectionFailure makes more sense here than AutoReconnect
--> 369                 raise ConnectionFailure(str(e))
    370 
    371         if username:

ConnectionFailure: [Errno 111] Connection refused

我为什么会遇到这个错误?我该如何修复它?在


Tags: inselfhostsizeinitportconnectiondocument
1条回答
网友
1楼 · 发布于 2024-04-18 01:47:54

当您不指定要连接的主机和端口时,就像不向Connection传递任何内容一样 connection = Connection()驱动程序试图连接到本地主机上的端口27017。在

由于失败,它强烈建议您没有在pymongo正在侦听端口27017的同一台计算机上运行mongod进程。在

如果您已经有了要连接到的MongoDB服务器,则必须指定其位置-主机和传递给连接的端口。在

相关问题 更多 >