DRF- 函数缺少 1 个必需的位置参数
DRF- function missing 1 required positional argument
我尝试在不使用模型的情况下将数据插入 mongodb。当我 运行 脚本出现以下错误时,
TypeError:get_db_handle() 缺少 1 个必需的位置参数:'password'
这是我的query.py
class Department(object):
print(object)
def import_department(self):
data = ["IT", "FINANCE", "HR"]
db_handle = self.get_db_handle(EVENT_STORE_DICT.get("DB_NAME"),
EVENT_STORE_DICT.get("DB_HOST"),
EVENT_STORE_DICT.get("DB_PORT"),
EVENT_STORE_DICT.get("USERNAME"),
EVENT_STORE_DICT.get("PASSWORD"))
department_insert = self.insert_into_db(db_handle, data)
if __name__ == '__main__':
Department.import_department(DBMixin)
此处,db 处理方法,
class DBMixin(object):
def get_db_handle(self, db_name, host, port, username, password)
client = MongoClient(host=host,
port=int(port),
username='',
password=''
)
db_handle = client[db_name]
return db_handle
我该如何解决这个问题。请帮帮我..
get_db_handle
是 class DBMixin
的一种方法,但您是从 class Department
调用它作为 self.get_db_handle()。
我尝试在不使用模型的情况下将数据插入 mongodb。当我 运行 脚本出现以下错误时,
TypeError:get_db_handle() 缺少 1 个必需的位置参数:'password'
这是我的query.py
class Department(object):
print(object)
def import_department(self):
data = ["IT", "FINANCE", "HR"]
db_handle = self.get_db_handle(EVENT_STORE_DICT.get("DB_NAME"),
EVENT_STORE_DICT.get("DB_HOST"),
EVENT_STORE_DICT.get("DB_PORT"),
EVENT_STORE_DICT.get("USERNAME"),
EVENT_STORE_DICT.get("PASSWORD"))
department_insert = self.insert_into_db(db_handle, data)
if __name__ == '__main__':
Department.import_department(DBMixin)
此处,db 处理方法,
class DBMixin(object):
def get_db_handle(self, db_name, host, port, username, password)
client = MongoClient(host=host,
port=int(port),
username='',
password=''
)
db_handle = client[db_name]
return db_handle
我该如何解决这个问题。请帮帮我..
get_db_handle
是 class DBMixin
的一种方法,但您是从 class Department
调用它作为 self.get_db_handle()。