这是文件下 djongo 代码的限制:'<>\Lib\site-packages\djongo\base.py'
def get_connection_params(self):
"""
Default method to acquire database connection parameters.
Sets connection parameters to match settings.py, and sets
default values to blank fields.
"""
valid_settings = {
'NAME': 'name',
'HOST': 'host',
'PORT': 'port',
'USER': 'username',
'PASSWORD': 'password',
'AUTH_SOURCE': 'authSource',
'AUTH_MECHANISM': 'authMechanism',
'ENFORCE_SCHEMA': 'enforce_schema',
'REPLICASET': 'replicaset',
'SSL': 'ssl',
'SSL_CERTFILE': 'ssl_certfile',
'SSL_CA_CERTS': 'ssl_ca_certs',
'READ_PREFERENCE': 'read_preference'
}
connection_params = {
'name': 'djongo_test',
'enforce_schema': True
}
for setting_name, kwarg in valid_settings.items():
try:
setting = self.settings_dict[setting_name]
except KeyError:
continue
if setting or setting is False:
connection_params[kwarg] = setting
return connection_params
在上面的代码中,valid_settings 字典应该还有一个键值对,即'SSL_CERT_REQS':'ssl_cert_reqs'。
此外,由于 ssl.CERT_NONE 为 0(IntEnum 中的第一个序数),所以我们需要再添加一个或条件 'setting == 0' 和 'setting or setting is False'
您可以手动添加此行,如果您在设置的 DATABASES 的默认字典中添加以下行,它应该可以工作:'SSL_CERT_REQS': ssl.CERT_NONE,
所以最终的更新方法如下:
def get_connection_params(self):
"""
Default method to acquire database connection parameters.
Sets connection parameters to match settings.py, and sets
default values to blank fields.
"""
valid_settings = {
'NAME': 'name',
'HOST': 'host',
'PORT': 'port',
'USER': 'username',
'PASSWORD': 'password',
'AUTH_SOURCE': 'authSource',
'AUTH_MECHANISM': 'authMechanism',
'ENFORCE_SCHEMA': 'enforce_schema',
'REPLICASET': 'replicaset',
'SSL': 'ssl',
'SSL_CERTFILE': 'ssl_certfile',
'SSL_CA_CERTS': 'ssl_ca_certs',
'READ_PREFERENCE': 'read_preference',
'SSL_CERT_REQS': 'ssl_cert_reqs'
}
connection_params = {
'name': 'djongo_test',
'enforce_schema': True
}
for setting_name, kwarg in valid_settings.items():
try:
setting = self.settings_dict[setting_name]
except KeyError:
continue
if setting or setting is False or setting == 0:
connection_params[kwarg] = setting
return connection_params