mongodb Mongoengine连接失败

mwyxok5s  于 2023-11-17  发布在  Go
关注(0)|答案(1)|浏览(228)

我试图为我的项目运行celery beat,但它给了我以下错误。
celery 工人运行良好。
使用Python 3.9
使用MongoDB:6.0.11

raise ConnectionFailure(err_msg)
mongoengine.connection.ConnectionFailure: A different connection with alias `default` was already registered. Use disconnect() first

字符串
已安装的软件包及其版本:
包版本

amqp 2.6.1
asgiref 3.7.2
4.0.3下载
台球3.6.4.0
boto3 1.28.65
botocore 1.31.65
瓶颈1.3.5
celery 4.4.7
celerybeat-mongo 0.2.0
证书2023.7.22
cffi 1.16.0
Chardet 5.2.0
Charset-normalizer 3.3.0
点击8.1.7
click-didyoumean 0.3.0
点击插件1.1.1
click-repl 0.3.0
简体中文
colorama 0.4.6
转换日期2.4.0
Coreapi 2.3.3
Coreschema 0.0.4
密码学41.0.4
循环仪0.12.1
简体中文
Django 4.2
django-encrypted-model-fields 0.6.5
django-rest-framework-mongoengine 3.4.1
django-rest-swagger 2.2.0
Djangorestframework 3.14.0
dnspython 2.4.2
docutils 0.20.1
Ephem 4.1.2
fernet 1.0.1
gevent 23.9.1
Greenlet 3.0.0
假期0.35
IDNA 3.4
简体中文
importlib-resources 6.1.0
itypes 1.2.0
Jinja2 3.1.2
jmespath 1.0.1
kiwisolver 1.4.4
kombu 4.6.11
LunarCalendar 0.0.9
MarkupSafe 2.1.3
Matplotlib 3.4.3
mkl-service 2.4.0
Mongoengine 0.20.0
numexpr 2.8.4
numpy 1.22.4
openapi-codec 1.3.2
Package 23.2
pandas 1.5.3
枕头9.4.0
点23.3
5.17.0下载
软件工具包3.0.39
先知1.1.4
pyaes 1.6.1
pycparser 2.21
PyMeeus 0.5.12
pymongo 3.13.0
pyparser 3.1.1
2.19.1.1
python-dateutil 2.8.2
pytz 2023.3.post1
Redis 5.0.1
请求2.31.0
s3transfer 0.7.0
scipy 1.11.3
安装工具68.0.0
简体中文(zh_cn)
六1.16.0
sqlparse 0.4.4
stanio 0.3.0
坚韧8.2.3
龙卷风6.2
tqdm 4.66.1
typing_extensions 4.8.0
tzdata 2023.3
uristemplate 4.1.1
简体中文
vine 1.3.0
wcwidth 0.2.8
车轮0.41.2
XlsxWriter 3.1.8
Zipp 3.17.0
zope.事件5.0
zope.interface 6.1

Traceback (most recent call last):
  File "C:\anaconda\envs\condaenv_python3.10\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\anaconda\envs\condaenv_python3.10\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\anaconda\envs\condaenv_python3.10\Scripts\celery.exe\__main__.py", line 7, in <module>
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\__main__.py", line 16, in main
    _main()
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\celery.py", line 322, in main
    cmd.execute_from_commandline(argv)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\celery.py", line 499, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\base.py", line 305, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\celery.py", line 491, in handle_argv
    return self.execute(command, argv)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\celery.py", line 415, in execute
    return cls(
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\base.py", line 308, in run_from_argv
    return self.handle_argv(prog_name,
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\base.py", line 393, in handle_argv
    return self(*args, **options)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\base.py", line 253, in __call__
    ret = self.run(*args, **kwargs)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\bin\beat.py", line 109, in run
    return beat().run()
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\apps\beat.py", line 81, in run
    self.start_scheduler()
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\apps\beat.py", line 100, in start_scheduler
    print(self.banner(service))
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\apps\beat.py", line 122, in banner
    c.reset(self.startup_info(service))),
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\apps\beat.py", line 132, in startup_info
    scheduler = service.get_scheduler(lazy=True)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celery\beat.py", line 657, in get_scheduler
    return symbol_by_name(self.scheduler_cls, aliases=aliases)(
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\celerybeatmongo\schedulers.py", line 127, in __init__
    self._mongo = mongoengine.connect(db, host=host, alias=alias)
  File "C:\anaconda\envs\condaenv_python3.10\lib\site-packages\mongoengine\connection.py", line 401, in connect
    raise ConnectionFailure(err_msg)
mongoengine.connection.ConnectionFailure: A different connection with alias `default` was already registered. Use disconnect() first


我尝试在连接mongoengine的代码中添加以下行
disconnect()
但是没有用
现在我希望celery 的节拍能跑起来

2ledvvac

2ledvvac1#

试试下面的代码

import mongoengine

mongoengine.disconnect(alias='default')

mongoengine.connect('your-db-name', alias='default')

字符串

相关问题