2012-11-09 5 views
5

Sto provando a scrivere uno script che scriverà su Google Docs Spreadsheet e quando lo eseguo ottengo l'errore nel titolo. Più in particolare:AttributeError: l'oggetto 'str' non ha attributo 'iteritems'

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' 

Il pezzo di codice che causa questo è:

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

Penso che "InsertRow" si aspetti che il primo parametro sia un dizionario che associa i valori ai nomi delle colonne, non una stringa. – eldarerathis

+0

Hai ragione penso - grazie per la risposta. – user1813343

risposta

1

No, la linea che causa l'errore è row_data.iteritems() perché row_data è una stringa e il metodo che si sta chiamando non è definito per la classe 'str'.

+0

Ho provato a convertire l'oggetto "data_str" in una stringa usando: 'data_str = str (data)' Dove 'data = commands.getoutput ('pcsensor')' - che è solo una data, ora e lettura del sensore. – user1813343