Anique Akhtar
Anique Akhtar

Reputation: 195

updating spreadsheet using gdata python api

READ THE UPDATE AT THE END FIRST Here's my code :

spreadsheet_key = "0AhBYO002ygGgdDZQTW5pTVhLdjM4NlhHbXJ1cVRCd3c"
worksheet_id = "od6"
spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = '[email protected]'
spr_client.password = '<pwd>'
spr_client.source = 'Example Spreadsheet Writing Application'
spr_client.ProgrammaticLogin()

dicti = {}
dicti['Name'] = 'A'
dicti['Metric Name'] = 'A2' 
dicti['Completed Units'] = 10
dicti['Team Size'] = 2
entry = spr_client.InsertRow(dicti, spreadsheet_key, worksheet_id)

Every time I run this code this error comes on the last time:

'int' object has no attribute 'decode'

Please tell me how I should proceed...

Here's where the error comes in the InsertRow function :

/usr/local/lib/python2.7/site-packages/gdata/spreadsheet/service.py in InsertRow
      new_custom.column = k
      new_custom.text = v
      new_entry.custom[new_custom.column] = new_custom
    # Generate the post URL for the worksheet which will receive the new entry.
    post_url = 'https://spreadsheets.google.com/feeds/list/%s/%s/private/full'%(
        key, wksht_id) 
    return self.Post(new_entry, post_url, 
        converter=gdata.spreadsheet.SpreadsheetsListFromString) 

UPDATE: After fixing this code to this:

dicti = {}
dicti['Name'] = 'A'
dicti['Metric Name'] = 'A2' 
dicti['Completed Units'] = '10'
dicti['Team Size'] = '2'

I get this error now:

{'status': 400, 'body': 'Attribute name &quot;Name&quot; associated with an element type &quot;ns1:Metric&quot; must be followed by the &#39; = &#39; character.', 'reason': 'Bad Request'}

Upvotes: 0

Views: 3445

Answers (2)

kimnhutminh
kimnhutminh

Reputation: 11

You just need to input column name in your:

Spreadsheet('name','metricname','completedunits','teamsize')

You can read more about it here.

Upvotes: 1

RocketDonkey
RocketDonkey

Reputation: 37249

You need to write string values when using the gdata API, so your 'Team Size' and 'Completed Units' variables will cause errors unless they are converted to strings. Also, you should be aware that the column names as referred to by the API do not retain your capitalization, etc. (your Metric Name column needs to be referred to as metricname). Therefore you also have to change how they appear in the dictionary (note that this assumes your column headers already exist, since the API needs to know how to write the dictionary):

dicti = {}
dicti['name'] = 'A'
dicti['metricname'] = 'A2' 
dicti['completedunits'] = '10'
dicti['teamsize'] = '2'
entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)

And as a side note (since this tripped me up for a bit), the same is true when using CellQuery objects and declaring the max and min values for ranges. Hope that helps avoid some confusion :)

Upvotes: 3

Related Questions