0

首先阅读最后的更新这是我的代码:

spreadsheet_key = "0AhBYO002ygGgdDZQTW5pTVhLdjM4NlhHbXJ1cVRCd3c"
worksheet_id = "od6"
spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = 'myemail@gmail.com'
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)

每次我运行此代码时,最后一次都会出现此错误:

'int' object has no attribute 'decode'

请告诉我应该如何进行...

这是 InsertRow 函数中出现错误的地方:

/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) 

更新:将此代码修复为:

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

我现在收到此错误:

{'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'}
4

2 回答 2

3

使用 gdata API 时需要写入字符串值,因此您的“团队规模”和“已完成单位”变量将导致错误,除非将它们转换为字符串。此外,您应该注意,API 引用的列名不保留您的大小写等(您的Metric Name列需要称为metricname)。因此,您还必须更改它们在字典中的显示方式(请注意,这假设您的列标题已经存在,因为 API 需要知道如何编写字典):

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

顺便说一句(因为这让我有点困惑),在使用CellQuery对象并声明范围的maxandmin值时也是如此。希望这有助于避免一些混乱:)

于 2012-10-13T00:16:39.477 回答
1

您只需要在您的:

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

你可以在这里阅读更多关于它的信息。

于 2013-04-13T00:12:16.573 回答