我正在尝试使用python 2.7上的python caldav库(版本0.5.0)修改日历。我正在使用以下代码段向重复发生的事件添加一个exdate
for event in results:
vevent = event.instance.vevent
if vevent.status.value != "CANCELLED":
if (vevent.summary.value, vevent.dtstart.value) in cancelled:
ev = calendar.event_by_uid(vevent.uid.value)
ev.instance.vevent.add("exdate").value = vevent.dtstart.value
print ev.instance.vevent.serialize()
虽然vobject库声称支持datetime对象,但最后一行失败了:
Traceback (most recent call last):
File "./caldavTest.py", line 31, in <module>
print ev.instance.vevent.serialize()
File "/usr/lib/python2.7/site-packages/vobject/base.py", line 254, in serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/python2.7/site-packages/vobject/behavior.py", line 166, in serialize
out = base.defaultSerialize(transformed, buf, lineLength)
File "/usr/lib/python2.7/site-packages/vobject/base.py", line 1007, in defaultSerialize
child.serialize(outbuf, lineLength, validate=False)
File "/usr/lib/python2.7/site-packages/vobject/base.py", line 254, in serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/python2.7/site-packages/vobject/behavior.py", line 160, in serialize
transformed = obj.transformFromNative()
File "/usr/lib/python2.7/site-packages/vobject/base.py", line 226, in transformFromNative
raise NativeError(msg, lineNumber)
vobject.base.NativeError: "In transformFromNative, unhandled exception on line None <type 'exceptions.TypeError'>: 'datetime.datetime' object has no attribute '__getitem__'"
有什么想法吗?