Hi,

I'm chemist and a coding novice. I have created a simple program with python 
that generates volume dispensing instructions for an instrument. I'd like to 
write the instructions into a spreadsheet and later pull them out with 
LabView, which I'll be using to control the instrument. 

I've installed gdata-2.0.14 and confirmed that I can connect to my google 
account through python, as I'm able to print out the list of my google docs 
using one of the gdata examples. However, I have been unsuccessful in 
writing to a spreadsheet. A short bit of test code I'm using (borrowed from 
http://www.mattcutts.com/blog/write-google-spreadsheet-from-python/) is 
copied below.

The output from the code is:

{'date': '05/09/2011', 'weight': '180', 'time': '21:36:31'}

Traceback (most recent call last):
  File "/Users/1/gdata-2.0.14/Python_to_GdSpr_Test2.py", line 27, in 
<module>
    gd_client.InsertRow(dict, spreadsheet_key, worksheet_id)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gdata/spreadsheet/service.py",
 
line 336, in InsertRow
    converter=gdata.spreadsheet.SpreadsheetsListFromString)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gdata/service.py",
 
line 1236, in Post
    media_source=media_source, converter=converter)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gdata/service.py",
 
line 1358, in PostOrPut
    'reason': server_response.reason, 'body': result_body}
RequestError: {'status': 400, 'body': 'We&#39;re sorry, a server error 
occurred. Please wait a bit and try reloading your spreadsheet.', 'reason': 
'Bad Request'}


How should I proceed to avoid the error?


Another question is: can I write from a tuple to a spreadsheet, or does it 
have to be a from dictionary? 


Thanks 



Python Code:

#!/usr/bin/python
#


import gdata.spreadsheet.service
import time

email = '[email protected]'
password = '[password]'
spreadsheet_key = 'tlomWx6mou3d7PRobvImARg'
worksheet_id = 'od6'

gd_client = gdata.spreadsheet.service.SpreadsheetsService(spreadsheet_key, 
worksheet_id)
gd_client.email = email
gd_client.password = password
gd_client.ProgrammaticLogin()


weight = '180'

dict = {}
dict['date'] = time.strftime('%m/%d/%Y')
dict['time'] = time.strftime('%H:%M:%S')
dict['weight'] = weight
print dict

gd_client.InsertRow(dict, spreadsheet_key, worksheet_id)

entry = gd_client.InsertRow(dict, spreadsheet_key, worksheet_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
    print "Insert row succeeded."
else:
    print "Insert row failed."

Reply via email to