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 を使用する場合は文字列値を書き込む必要があるため、'Team Size' 変数と 'Completed Units' 変数は、文字列に変換しないとエラーが発生します。また、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宣言する場合も同じことが当てはまります。混乱を避けるのに役立つことを願っています:)maxmin

于 2012-10-13T00:16:39.477 に答える
1

次の列に列名を入力するだけです。

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

詳細については、こちらをご覧ください。

于 2013-04-13T00:12:16.573 に答える