これを使用してスプレッドシートに行を単純に挿入しようとしています:
# this is how I create the spreadsheet document
doc_client = getDocAPIService(user_id) # a separate function handles oauth and returns the doc client
doc = gdata.docs.data.Resource(type='spreadsheet', title='test')
doc = doc_client.CreateResource(doc)
spreadsheet_key = doc.GetId().split("%3A")[1]
# I then try to manipulate the spreadsheet
fields = {'test': 'test'}
sheet_client = getSpreadhseetAPIService() # again, a separate function handles oauth
entry = sheet_client.InsertRow(fields, spreadsheet_key, wksht_id='od6')
ワークシートを追加してフィードなどを取得することはできますが、行を追加すると次のエラーが発生します。
TypeError: unbound method _AddMembersToElementTree() must be called with ExtensionContainer instance as first argument (got SpreadsheetsList instance instead)
これらは、重要な場合に備えて、クライアントを取得して oauth を処理するためのヘルパー関数です。
def getDocAPIService(username):
two_legged_oauth_token = gdata.gauth.TwoLeggedOAuthHmacToken(
config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET, username)
client_docs = MyDocsClient(source="myapp")
client_docs.auth_token = two_legged_oauth_token
client_docs.ssl = True
client_docs.http_client.debug = True
client_docs.http_client.deadline = 30
return client_docs
def getSpreadhseetAPIService():
gdocs = gdata.spreadsheet.service.SpreadsheetsService(source="myapp")
gdocs.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET)
gdata.alt.appengine.run_on_appengine(gdocs)
return gdocs
これは完全なトレースバックです:
Traceback (most recent call last):
File "/path_to_project/tornado/web.py", line 954, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "/path_to_project/tornado/web.py", line 1667, in wrapper
return method(self, *args, **kwargs)
File "/path_to_project/script.py", line 999, in get
doc = generateSpreadsheetFromTemplate(template, current_user.email())
File "/path_to_project/utils.py", line 183, in generateSpreadsheetFromTemplate
entry = sheet_client.InsertRow(fields, spreadsheet_key, wksht_id='od6')
File "/path_to_project/gdata/spreadsheet/service.py", line 339, in InsertRow
converter=gdata.spreadsheet.SpreadsheetsListFromString)
File "/path_to_project/gdata/service.py", line 1236, in Post
media_source=media_source, converter=converter)
File "/path_to_project/gdata/service.py", line 1322, in PostOrPut
headers=extra_headers, url_params=url_params)
File "/path_to_project/atom/__init__.py", line 93, in optional_warn_function
return f(*args, **kwargs)
File "/path_to_project/gdata/atom/service.py", line 176, in request
content_length = CalculateDataLength(data)
File "/path_to_project/gdata/atom/service.py", line 736, in CalculateDataLength
return len(str(data))
File "/path_to_project/gdata/atom/__init__.py", line 377, in __str__
return self.ToString()
File "/path_to_project/gdata/atom/__init__.py", line 374, in ToString
return ElementTree.tostring(self._ToElementTree(), encoding=string_encoding)
File "/path_to_project/gdata/atom/__init__.py", line 369, in _ToElementTree
self._AddMembersToElementTree(new_tree)
File "/path_to_project/gdata/spreadsheet/__init__.py", line 372, in _AddMembersToElementTree
atom.ExtensionContainer._AddMembersToElementTree(self, tree)
TypeError: unbound method _AddMembersToElementTree() must be called with ExtensionContainer instance as first argument (got SpreadsheetsList instance instead)
これはなぜですか?
ありがとう、
アービー