我正在尝试使用以下方法在电子表格中简单地插入一行:
# 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)
知道为什么会这样吗?
谢谢,
阿比