【问题标题】:How do I fix these errors?如何修复这些错误?
【发布时间】:2019-06-14 07:57:03
【问题描述】:

我有一个 sqlite3 数据库 django 应用程序。我试图使用 djongo 切换到 MongoDB Atlas。但我不知道如何修复这些错误

我安装了 djongo

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'test',
        'HOST': 'mongodb+srv://<username>:<password>@cluster0-bs91f.mongodb.net/test?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority',
        'USERNAME': '<username>',
        'PASSWORD': '<password>',
    }
}

这是我在 settings.py 中唯一改变的地方

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
    loader.check_consistent_history(connection)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/loader.py", line 283, in check_consistent_history
    applied = recorder.applied_migrations()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
    return get_names(cursor)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/djongo/introspection.py", line 46, in get_table_list
    for c in cursor.db_conn.collection_names(False)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/database.py", line 787, in collection_names
    nameOnly=True, **kws)]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/database.py", line 725, in list_collections
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/database.py", line 675, in _list_collections
    session=tmp_session)["cursor"]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/database.py", line 555, in _command
    client=self.__client)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/pool.py", line 584, in command
    user_fields=user_fields)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/network.py", line 158, in command
    parse_write_concern_error=parse_write_concern_error)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/helpers.py", line 155, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: unsupported type in filter

我不断收到这些错误。我不知道如何解决它们

【问题讨论】:

  • 你能提供更多细节吗?什么触发了这个错误?
  • 请向我们展示完整错误回溯,包括最后一行中的实际错误。
  • 我现在对其进行了编辑以包含完整的回溯

标签: python django mongodb mongodb-atlas djongo


【解决方案1】:

您需要使用 urllib.parse 包解析您的密码(可能还需要登录)才能与 Pymongo 连接:

'password': urllib.parse.quote_plus("<password>")

【讨论】:

  • 我没有使用任何特殊字符
【解决方案2】:

如果您在密码中使用特殊字符,则会出现错误。请使用parse 或更改您的密码

【讨论】:

  • 密码没有特殊字符
猜你喜欢
  • 2015-04-23
  • 1970-01-01
  • 2018-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-01
  • 2021-05-06
相关资源
最近更新 更多