2016-07-29 70 views
0

我试图抓住给定工作表的所有单元格历史并将其吐出到csv。代码在一张纸上工作,但不在另一张上。当我到达代码的修订部分时,出现一堆属性错误。以下代码是循环遍历工作表单元格的函数的内核。Smartsheet错误对象 - 属性错误

错误读取'Error' object has no attribute 'data'

最奇怪的是,这些错误并不一致地发现。就像在循环同一张表格一样,不同的单元格会比上次运行脚本时弹出错误。我正在捕捉属性错误,但这并不能真正解决问题。帮帮我?

  #get the cell history 
      action = smartsheet.Cells.get_cell_history(
       sheetid, 
       row.id, 
       columns[c].id, 
       #include_all=True 
       ) 

      try: 
       revisions = action.data 

      except AttributeError as inst: 
       print('found Attribute error in this cell:') 
       print(inst) 

回答

0

这可能是因为该单元格没有历史记录。在访问它之前,您需要进行安全检查以验证该属性是否存在。

if not hasattr(action, 'data'): 
    print('no history found') 

你可能是轮询API过快,这就是为什么有时候不返回值。来自API documentation

这是一项资源密集型操作,并针对速率限制产生10个附加请求。

确保您正确处理任何返回的错误以查看是否属于这种情况。