0

我试图从我的数据表中的一行返回一个值,并收到以下错误:

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, model, year, engine, drive, 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, model, year, engine, drive, axle))
  gvwr_truck = int(get_gvwr_truck(brand, model, year, engine, drive, axle))
  base_weight = int(get_base_weight(gvwr_truck, payload))
  gvw = base_weight + passengers + cargo + hitch
  value = gcwr - gvw
  return value

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

“卡车规格”数据表图像

4

1 回答 1

0

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

于 2021-07-05T17:18:30.720 回答