Google Cal API Python:多次删除且 ExecuteBatch 失败

发布于 2024-12-08 17:23:54 字数 1850 浏览 2 评论 0原文

我尝试使用 Google API for python 删除日历的所有事件。 如果我一一删除事件,这可以正常工作,但它很长并且没有优化,因此我尝试使用 ExecuteBatch 执行相同的操作,我用它在日历中插入大量条目(并且在插入之前工作正常)。

def DeleteAllEntryOfCalendar(calendar_client, name_calendar):
    #Request_feed for doing the delete
    request_feed = gdata.calendar.CalendarEventFeed()
    #Get the Uri of the cal we've to delete all entries
    uri = GetUri(calendar_client, name_calendar)
    feed = calendar_client.GetAllCalendarsFeed()
    for a_cal in feed.entry:
        if a_cal.title.text == name_calendar:
            calendar = a_cal    
    #For each entry in the cal, do a delete request entry in request_feed
    query = gdata.calendar.client.CalendarEventQuery()
    query.max_results = 1000
    feed = calendar_client.GetCalendarEventFeed(uri=uri, q=query)
    for an_entry in feed.entry:
        an_entry.batch_id = gdata.BatchId(text='delete-request')
        request_feed.AddDelete(entry=an_entry)    
        entry = ''

    # submit the batch request to the server
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')

我收到错误:

Traceback (most recent call last):
  File "c.py", line 253, in <module>
    DeleteAllEntryOfCalendar(client, name_calendar)
  File "c.py", line 187, in DeleteAllEntryOfCalendar
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')
  File "/usr/local/lib/python2.6/dist-packages/gdata/calendar/client.py", line 432, in     execute_batch
    return self.Post(batch_feed, url, desired_class=desired_class)
  File "/usr/local/lib/python2.6/dist-packages/gdata/client.py", line 681, in post
    entry.to_string(get_xml_version(self.api_version)),
AttributeError: 'CalendarEventFeed' object has no attribute 'to_string'

我重复一遍,当我执行相同操作来插入事件时,效果很好。 我进行了很多搜索并尝试了很多可能性,但我无法做到这一点。 如果你有一个想法...

I try to delete all the events of a calendar using the Google API for python.
If I delete the events one by one this works fine but it's very long and not unoptimized so I try to do the same thing using ExecuteBatch that I use for insert a lot of entries in the calendar (and this works fine before the insert).

def DeleteAllEntryOfCalendar(calendar_client, name_calendar):
    #Request_feed for doing the delete
    request_feed = gdata.calendar.CalendarEventFeed()
    #Get the Uri of the cal we've to delete all entries
    uri = GetUri(calendar_client, name_calendar)
    feed = calendar_client.GetAllCalendarsFeed()
    for a_cal in feed.entry:
        if a_cal.title.text == name_calendar:
            calendar = a_cal    
    #For each entry in the cal, do a delete request entry in request_feed
    query = gdata.calendar.client.CalendarEventQuery()
    query.max_results = 1000
    feed = calendar_client.GetCalendarEventFeed(uri=uri, q=query)
    for an_entry in feed.entry:
        an_entry.batch_id = gdata.BatchId(text='delete-request')
        request_feed.AddDelete(entry=an_entry)    
        entry = ''

    # submit the batch request to the server
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')

And I got the error :

Traceback (most recent call last):
  File "c.py", line 253, in <module>
    DeleteAllEntryOfCalendar(client, name_calendar)
  File "c.py", line 187, in DeleteAllEntryOfCalendar
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')
  File "/usr/local/lib/python2.6/dist-packages/gdata/calendar/client.py", line 432, in     execute_batch
    return self.Post(batch_feed, url, desired_class=desired_class)
  File "/usr/local/lib/python2.6/dist-packages/gdata/client.py", line 681, in post
    entry.to_string(get_xml_version(self.api_version)),
AttributeError: 'CalendarEventFeed' object has no attribute 'to_string'

I repeat that when I do the same to insert events this works fine.
I've search a lot and tried a lot of possibilities and I can't do it work.
If you've an idea...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2024-12-15 17:23:54

使用

gdata.calendar.data.CalendarEventFeed

gdata python 库中的某些对象有两个版本,您不能将它们混合在一起。

Use

gdata.calendar.data.CalendarEventFeed

Some objects in gdata python library have two versions and you cannot mix them together.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文