我尝试制作一个应用程序来读取 Outlook 共享日历中的事件。我在 win10 上使用 Python 3.8.0。这是我的功能。
def getSharedCalendarEntries(TS_name, days=1000): #TS_name is name of shared calendar
MailboxToAccess = 'owner@gmail.com'
Outlook = win32com.client.Dispatch("Outlook.Application")
namespace = Outlook.GetNamespace("MAPI")
recipient = namespace.createRecipient(MailboxToAccess)
resolved = recipient.Resolve()
sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9).Folders(TS_name).Items
sharedCalendar.Sort("[Start]")
sharedCalendar.IncludeRecurrences = 'True'
today = datetime.datetime(2019,1,1)
begin = today.date().strftime('%d/%m/%Y')
tomorrow = datetime.timedelta(days=days)+today
end = tomorrow.date().strftime('%d/%m/%Y')
sharedCalendar = sharedCalendar.Restrict("[Start] >= '" +begin+ "' AND [END] <= '" +end+ "'")
events = {'Start':[],'End':[],'Subject':[],'Duration':[]}
mEv = []
for app in sharedCalendar: #petla po rezerwacjach
adate = datetime.datetime(app.Start.year, app.Start.month, app.Start.day).date()
events['Start'].append(adate)
aend = datetime.datetime(app.End.year, app.End.month, app.End.day).date()
events['End'].append(aend)
events['Duration'].append(int(app.Duration/1440))
events['Subject'].append(app.Subject)
mEvent = Event(adate, aend, int(app.Duration/1440), app.Subject)
mEv.append(mEvent)
return mEv
一切正常,我能够读取事件,但突然发生了一些事情(我没有更改代码中的任何内容)并且我有这样的错误:
文件“C:\Users\user_catalog\Desktop\outread.py”,第 60 行,在 getSharedCalendarEntries sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9).Folders(TS_name).Items
文件“C:\Users\user_catalog\AppData\Local\Programs\Python\Python38\lib\site-packages\win32com\client\dynamic.py”,第 197 行,调用 return self._get_good_object_( self.oleobj .Invoke( *allArgs), self.olerepr .defaultDispatchName,None) pywintypes.com_error: (-2147352567, '发生异常。', (4096, 'Microsoft Outlook', '尝试执行操作失败。找不到对象。' , 无, 0, -2147221233), 无)
我拥有共享日历的只读访问权限。共享日历的所有者说她注销了网络,注销的时间与我的应用程序停止工作的时间相同。
你们有没有人遇到过这样的问题或对我有什么建议?先感谢您!
皮奥