You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

传递多变量至函数时触发TypeError:get_entity_id()参数数量不匹配

解决TypeError: get_entity_id() takes 2 positional arguments but 4 were given错误

问题场景

从AJAX表单获取用户输入:

getFormData = (request.form)
reportName = (getFormData['reportName'])
districtName = (getFormData['districtName'])
rapid7Query = (getFormData['rapid7Query'])
rapid7SeverityLevel = (getFormData['rapid7SeverityLevel'])

将参数传入check_action函数:

print("In post request response...")

response = insightvmreport.check_action(reportName, districtName, rapid7Query, rapid7SeverityLevel)

在check_action中调用get_entity_id时触发错误:

def check_action(reportName, districtName, rapid7Query, rapid7SeverityLevel):
    print(reportName, districtName, rapid7Query, rapid7SeverityLevel)
    action = "download"
    if action == "download":
        # 此处传了4个参数给get_entity_id,但它只接受2个
        scan_id,site_id = get_entity_id(reportName, districtName, rapid7Query, rapid7SeverityLevel)
        if scan_id and site_id:
            response = configure_report(scan_id,site_id)
            return response

完整错误栈:

test District 1 (EUR) SELECT * FROM dim_asset ORDER BY ip_address ASC Medium
[2022-09-21 11:48:05,216] ERROR in app: Exception on /rapid7/submit_report/process [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/s153152/Documents/Workspace/ssd_dashboard/app/bin/auth_functions.py", line 52, in decorated_view
    return func(*args, **kwargs)
  File "/Users/s153152/Documents/Workspace/ssd_dashboard/app/views/rapid7/view.py", line 44, in process
    response = insightvmreport.check_action(reportName, districtName, rapid7Query, rapid7SeverityLevel)
  File "/Users/s153152/Documents/Workspace/ssd_dashboard/services/rapid7/insightvmreport.py", line 19, in check_action
    scan_id,site_id = get_entity_id(reportName, districtName, rapid7Query, rapid7SeverityLevel)
TypeError: get_entity_id() takes 2 positional arguments but 4 were given

错误原因

get_entity_id函数的定义只接受2个位置参数,但调用时传入了4个参数(reportName, districtName, rapid7Query, rapid7SeverityLevel),导致参数数量不匹配。

解决方法

方法一:调整调用参数,只传函数需要的2个参数

先找到get_entity_id的定义,确认它实际需要的参数。比如如果它只需要reportName和districtName,就修改调用代码:

scan_id,site_id = get_entity_id(reportName, districtName)

方法二:修改get_entity_id的定义,接受4个参数

如果get_entity_id确实需要这四个参数来生成scan_id和site_id,就更新函数定义:

def get_entity_id(reportName, districtName, rapid7Query, rapid7SeverityLevel):
    # 原函数逻辑,使用这四个参数处理并返回scan_id和site_id
    scan_id = ...
    site_id = ...
    return scan_id, site_id

内容的提问来源于stack exchange,提问作者FloydLee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 10:55:14