Anvil 错误:TypeError:'NoneType' 对象不可下标

问题描述

我试图从数据表中的一行返回一个值,但出现以下错误

TypeError: 'nonetype' 对象不可下标(键 'GCWR')

这是错误中引用的代码片段...

"""
This function gets the GCWR of the truck from the 'truck_specifications' data table
Parameters: brand,model,year,engine,drive,axle
Returns: gcwr
"""
def get_gcwr(brand,axle):
  gcwr_row = app_tables.truck_specifications.get(Brand=brand,Model=model,Year=year,Engine_Type=engine,Drive_Type=drive,Axle_Ratio=axle)
  gcwr = gcwr_row['GCWR']
  return gcwr

一些细节:

  • 变量“gcwr”应该根据上面显示的参数从数据表中的特定行返回一个数字
  • 这以前有效,但是当我开始向表中添加更多数据时,它现在给了我如上所示的错误
  • 我根据参数手动查看了数据表,有一行符合条件,应该返回值
  • 数据表中列的数据类型为“数字”

这是调用上述函数代码片段...

"""
This function gets the truck specifications based on the users input
Parameters: none
Returns: value (allowable trailer GVWR)
"""
@anvil.server.callable
def get_truck_specifications():
  
  # Get data from 'truck_inputs' data table
  brand = get_brand()
  model = get_model()
  year = get_year()
  engine = get_engine()
  drive = get_drive()
  axle = get_axle()
  payload = int(get_payload())
  passengers = int(get_passengers())
  cargo = int(get_cargo())
  hitch = int(get_hitch())
  
  # Get data from 'truck_specifications' data table
  gcwr = int(get_gcwr(brand,axle))
  gvwr_truck = int(get_gvwr_truck(brand,axle))
  base_weight = int(get_base_weight(gvwr_truck,payload))
  gvw = base_weight + passengers + cargo + hitch
  value = gcwr - gvw
  return value

这是显示数据表示例的屏幕截图...

'Truck Specifications' data table image

解决方法

在我实现上传器后,数据表中的列似乎没有正确标记(相对于手动添加数据)。重新标注后,问题解决。