gpt4 book ai didi

python - mongoengine.connection.ConnectionError : Cannot connect to database default : [Errno 111] Connection refused

转载 作者:太空宇宙 更新时间:2023-11-04 00:59:30 31 4
gpt4 key购买 nike

我在将 mongoengine 合并到我的 django 应用程序时遇到问题。以下是我收到的错误:

Traceback (most recent call last):
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 374, in __init__
self._ensure_connected(True)
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 939, in _ensure_connected
self.__ensure_member()
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 813, in __ensure_member
member, nodes = self.__find_node()
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 904, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 133, in get_connection
_connections[alias] = connection if connection else connection_class(**conn_settings)
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 377, in __init__
raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "create_admin.py", line 7, in <module>
connect('happy_lens')
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 173, in connect
return get_connection(alias)
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 135, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
[Errno 111] Connection refused

下面是我要运行的代码:

import getpass

from mongoengine import connect

from models import User

connect('happy_lens')

admin = User(username='dk', email='someemail@gmail.com')
admin.password='pwd'
admin.save()

下面是相关的settings.py代码:

DATABASES = {
'default' : {
'ENGINE': 'django_mongodb_engine',
'NAME': 'happy_lens',
'HOST': '192.168.1.35',
'POST': 12345

}
}

SESSION_ENGINE = 'mongoengine.django.sessions'

我搜索过的所有内容都没有用。请帮忙。

最佳答案

所以我想出了我自己的问题。我是 mongo 的新手,所以我认为它的工作方式与 sqlalchemy 相同,其中 sqlite 数据库将在 pythonanywhere 平台中自动创建,但事实并非如此。

对于第一次将 pythonanywhere 与 mongo 结合使用的每个人,请确保获得外部服务(我在 Amazon AWS 上使用 MongoLab)。设置数据库后,您可以通过在 mongoengine.connect 函数中提供正确的 MongoDB URI 来连接到它。

关于python - mongoengine.connection.ConnectionError : Cannot connect to database default : [Errno 111] Connection refused,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515478/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com