求助使用过gdata-python-client的大神

失忆的鱼 2013-07-19 04:40:30
使用gdata-python-client ,如何向spreadsheet中插入和修改,删除数据:
网上资料很少,自己写了写老是报错,求大神指教
出错代码:(ps:就写了个插入,还差不进去,
import time
import gdata.spreadsheet.service

email = '1234567@gmail.com'
password = 'abcdefg'
weight = '180'

gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = email
gd_client.password = password
gd_client.source = 'Example Spreadsheet Writing Application'
gd_client.ProgrammaticLogin()

dict = {}
dict['test1'] = time.strftime('%m/%d/%Y')
dict['test'] = time.strftime('%H:%M:%S')
dict['1'] = weight
print dict

entry = gd_client.InsertRow(dict,"triXrHT_0E0X0ZMpvFJYO-A","od6")
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
print "Insert row succeeded."
else:
print "Insert row failed."
...全文
442 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
失忆的鱼 2013-07-20
  • 打赏
  • 举报
回复
引用 5 楼 panghuhu250 的回复:
[quote=引用 4 楼 qq525003138 的回复:] 对,我就是参考这篇文章写的,google的官方文档Google Spreadsheets API version 3.0也看了,没有python版的,是不是把python版的屏蔽了,不应该吧?
是我的错,没注意编程语言。有人提到用gd_client.debug = True可以得到更多的信息。还有人提到空表会出问题,先通过web UI建立表格,加上表头可以解决。http://code.google.com/p/gdata-python-client/issues/detail?id=481[/quote] 不是空表,我写有内容,现在就是只可以读取,其他操作都无法实现。 用了debug=true后的错误信息: send: 'POST https://spreadsheets.google.com/feeds/list/triXrHT_0E0X0ZMpvFJYO-A/od6/private/full HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: spreadsheets.google.com\r\nContent-Length: 247\r\nContent-Type: application/atom+xml\r\nAuthorization: GoogleLogin auth=DQAAAL8AAACzLFJgM7iMwRmYKG2vLJO6AbAF8fEDxIzh6LOo65YJpQvNZ8gzdyKT9Qe4nLETfsUSBmz_iFvf3yxbCZ9oXb-WbY5_bME_bS4XG3B2QTYgPj7IG5HAJYDLm-jfMxZXXal3HB4Nz3eDCx_JJ4VJD-ZRKWGEm_kbIh3S1f2mJpbLFXqYE1B7X8mCBwJkQV1DtBo9vJZsSCcNXTXwqUZ43swLSFPvCJXFLydyoi-TBddzxdUCMBrFSkhCx99xScj54Aw\r\nUser-Agent: Example Spreadsheet Writing Application GData-Python/2.0.18\r\n\r\n' send: '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:ns1="http://schemas.google.com/spreadsheets/2006/extended"><ns1:test1>07/20/2013</ns1:test1><ns1:test>03:24:37</ns1:test><ns1:1>180</ns1:1></ns0:entry>' reply: 'HTTP/1.1 400 Bad Request\r\n' header: Content-Type: text/html; charset=UTF-8 header: Set-Cookie: NID=67=SfujM9CqhjnbPcv0CV55k7OnNFcl9H0hQWZOYUYnjmZFHslHggRt00TokysVDFSzsJABcj-L5BAEaV-VbbB5pRqa-F2JGLVk1DtDAoEbT_Glddfl87kRsBst3C-LOYwu;Domain=.google.com;Path=/;Expires=Sun, 19-Jan-2014 03:27:33 GMT;HttpOnly header: P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info." header: x-chromium-appcache-fallback-override: disallow-fallback header: Date: Sat, 20 Jul 2013 03:27:33 GMT header: Expires: Sat, 20 Jul 2013 03:27:33 GMT header: Cache-Control: private, max-age=0 header: X-Content-Type-Options: nosniff header: X-Frame-Options: SAMEORIGIN header: X-XSS-Protection: 1; mode=block header: Server: GSE header: Transfer-Encoding: chunked Traceback (most recent call last): File "spreadsheet3.py", line 24, in <module> entry = gd_client.InsertRow(dict,"triXrHT_0E0X0ZMpvFJYO-A","od6") File "/usr/local/lib/python2.7/dist-packages/gdata/spreadsheet/service.py", line 339, in InsertRow converter=gdata.spreadsheet.SpreadsheetsListFromString) File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1236, in Post media_source=media_source, converter=converter) File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1358, in PostOrPut 'reason': server_response.reason, 'body': result_body} gdata.service.RequestError: {'status': 400, 'body': 'Element or attribute do not match QName production: QName::=(NCName':')?NCName. ', 'reason': 'Bad Request'}
panghuhu250 2013-07-20
  • 打赏
  • 举报
回复
引用 4 楼 qq525003138 的回复:
对,我就是参考这篇文章写的,google的官方文档Google Spreadsheets API version 3.0也看了,没有python版的,是不是把python版的屏蔽了,不应该吧?
是我的错,没注意编程语言。有人提到用gd_client.debug = True可以得到更多的信息。还有人提到空表会出问题,先通过web UI建立表格,加上表头可以解决。http://code.google.com/p/gdata-python-client/issues/detail?id=481
失忆的鱼 2013-07-20
  • 打赏
  • 举报
回复
引用 2 楼 panghuhu250 的回复:
这片文章中的代码和你的代码很类似,http://www.mattcutts.com/blog/write-google-spreadsheet-from-python/,这文章是09年的,gdata API已经变了。比如 gdata.spreadsheet.service.SpreadsheetsService根本没有insertRow方法。 google的官方文档(https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row)就很详细。
对,我就是参考这篇文章写的,google的官方文档Google Spreadsheets API version 3.0也看了,没有python版的,是不是把python版的屏蔽了,不应该吧?
失忆的鱼 2013-07-20
  • 打赏
  • 举报
回复
引用 1 楼 panghuhu250 的回复:
复制全部错误信息出来。
{'test1': '07/19/2013', 'test': '08:14:40', '1': '180'} Traceback (most recent call last): File "spreadsheet3.py", line 23, in <module> entry = gd_client.InsertRow(dict,"triXrHT_0E0X0ZMpvFJYO-A","od6") File "/usr/local/lib/python2.7/dist-packages/gdata/spreadsheet/service.py", line 339, in InsertRow converter=gdata.spreadsheet.SpreadsheetsListFromString) File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1236, in Post media_source=media_source, converter=converter) File "/usr/local/lib/python2.7/dist-packages/gdata/service.py", line 1358, in PostOrPut 'reason': server_response.reason, 'body': result_body} gdata.service.RequestError: {'status': 400, 'body': 'Element or attribute do not match QName production: QName::=(NCName':')?NCName. ', 'reason': 'Bad Request'}
panghuhu250 2013-07-20
  • 打赏
  • 举报
回复
搜索发现“Element or attribute do not match QName production: QName::=(NCName':')?NCName.”不是gdata独有的错误信息,是和xml有关的。把这儿提到的xml: send: '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<ns0:entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:ns1="http://schemas.google.com/spreadsheets/2006/extended"><ns1:test1>07/20/2013</ns1:test1><ns1:test>03:24:37</ns1:test><ns1:1>180</ns1:1></ns0:entry>' 用在线xml validator检查,有的指出ns1:1处有问题,把1改成字母就好了。也许不能用数字做列名?把这一列去掉试试。
panghuhu250 2013-07-19
  • 打赏
  • 举报
回复
这片文章中的代码和你的代码很类似,http://www.mattcutts.com/blog/write-google-spreadsheet-from-python/,这文章是09年的,gdata API已经变了。比如 gdata.spreadsheet.service.SpreadsheetsService根本没有insertRow方法。 google的官方文档(https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row)就很详细。
panghuhu250 2013-07-19
  • 打赏
  • 举报
回复
复制全部错误信息出来。

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧