2

所以这很令人担忧——我希望有人能帮我解决这个问题。

我正在使用 python 脚本下载 google doc 电子表格,然后将它们备份到我们的服务器。大多数时候,它运行良好,但我经常会收到如下所示的错误:

gdata.service.RequestError: {'status': 409, 'body': '', 'reason': 'Conflict'}

这是我正在使用的所有代码。有人知道 Export 函数是否有一些可能导致这种情况的奇怪行为吗?

QC_GoogleDoc_Spreadsheet_AutoLog
Author: Christopher James Johnson
Date: May 22, 2012

try:
  from xml.etree import ElementTree
except ImportError:
  from elementtree import ElementTree
import gdata.spreadsheet.service
import gdata.service
import atom.service
import gdata.spreadsheet
import gdata.docs.service
import atom
import getopt
import sys
import string
import time
import shutil
import os
import getpass
import tempfile
import csv
import time
import datetime
import glob


def main():

    archiver = backUpper()


class backUpper():

  def __init__(self):





gd = gdata.docs.service.DocsService()    


self.gd_client = gdata.docs.service.DocsService()  
self.gd_client.email = 'xxxx.xxxx'
self.gd_client.password = 'xxxxxxxx'
self.gd_client.source = 'Spreadsheets GData Sample'
self.gd_client.ProgrammaticLogin()
self.curr_key = ''
self.curr_wksht_id = ''
self.list_feed = None
self.autoLogPath = ""


spreadsheets_client = gdata.spreadsheet.service.SpreadsheetsService()
spreadsheets_client.email = self.gd_client.email
spreadsheets_client.password = self.gd_client.password
spreadsheets_client.source = "My Fancy Spreadsheet Downloader"
spreadsheets_client.ProgrammaticLogin()

feed = spreadsheets_client.GetSpreadsheetsFeed()

for i, entry in enumerate(feed.entry):
  if isinstance(feed, gdata.spreadsheet.SpreadsheetsSpreadsheetsFeed):
    if isinstance(entry, gdata.spreadsheet.SpreadsheetsSpreadsheet):
      print entry.title.text
      x = entry.id.text
      print x
      self.Download(entry)


self.DeleteTemporaryFiles()


def Download(self, entry):
line = entry.id.text
title = entry.title.text
splitLine = line.split('/')
key = splitLine[-1]

backUpDir = R'\\cob-hds-1\compression\QC\QCing\otherFiles\GoogleDocBackUp' + '\\'

now = datetime.datetime.now()
hour = now.hour
today = datetime.date.today()
if not os.path.exists(backUpDir + str(today)):
  os.mkdir(backUpDir + str(today))
if not os.path.exists(backUpDir + str(today) + '\\' + str(hour)):
  os.mkdir(backUpDir + str(today) + '\\' + str(hour))

backupDir = backUpDir + str(today) + '\\' + str(hour)

tempfile.tempdir = backupDir
file_path = tempfile.mkstemp(suffix='.xls')    

uri = 'http://docs.google.com/feeds/documents/private/full/%s' % key

spreadsheets_client = gdata.spreadsheet.service.SpreadsheetsService()
spreadsheets_client.email = self.gd_client.email
spreadsheets_client.password = self.gd_client.password
spreadsheets_client.source = "My Fancy Spreadsheet Downloader"
spreadsheets_client.ProgrammaticLogin()

# ...
docEntry = self.gd_client.GetDocumentListEntry(uri)

docs_auth_token = self.gd_client.GetClientLoginToken()
self.gd_client.SetClientLoginToken(spreadsheets_client.GetClientLoginToken())
self.gd_client.Export(docEntry, file_path[1])
shutil.copy(file_path[1], backupDir + '//' + title + '.xls')


os.close(file_path[0])
self.gd_client.SetClientLoginToken(docs_auth_token)     


if __name__ == '__main__':
main()

所以可怕的部分——今天早上才开始发生!之前一切都很好......今天早上......这个和其他使用python脚本的Gdata已经开始发生了一些事情!请帮忙!

谢谢!

编辑:所以我的一位同事当时正在处理其中一个电子表格,我们的两个程序都崩溃了。(我的备份了谷歌文档和他写的内容。如果我们同时处理同一个电子表格,这会产生问题吗?)

4

0 回答 0