【问题标题】:AttributeError: 'str' object has no attribute 'iteritems'AttributeError:“str”对象没有属性“iteritems”
【发布时间】:2012-10-30 05:34:13
【问题描述】:

我正在尝试编写一个脚本,该脚本将写入 Google Docs 电子表格,当我运行它时,标题中出现错误。更具体地说:

File "/home/pi/Desktop/templog.py", line 44, in <module>
    s.run()
  File "/usr/lib/python2.7/sched.py", line 117, in run
    action(*argument)
  File "/home/pi/Desktop/templog.py", line 35, in do_something
    entry = spr_client.InsertRow(data_str, spreadsheet_key, worksheet_id)
  File "/usr/local/lib/python2.7/dist-packages/gdata/spreadsheet/service.py", line 330, in          InsertRow
for k, v in row_data.iteritems():
AttributeError: 'str' object has no attribute 'iteritems'

导致这种情况的代码是:

entry = spr_client.InsertRow(data_str, spreadsheet_key, worksheet_id)
        if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):

【问题讨论】:

  • 我认为InsertRow 期望第一个参数是将值映射到列名的字典,而不是字符串。
  • 我认为你是对的 - 感谢您的回复。

标签: attributeerror


【解决方案1】:

不,导致错误的行是 row_data.iteritems(),因为 row_data 是一个字符串,而您调用的方法没有为类 'str' 定义。

【讨论】:

  • 我尝试使用以下方法将“data_str”对象转换为字符串:data_str=str(data) 其中data=commands.getoutput('pcsensor') - 这只是日期、时间和传感器读数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-10
  • 2021-10-04
  • 2019-12-02
  • 2021-09-25
  • 2014-03-04
相关资源
最近更新 更多