Python3.7挂起获取约会项目的Outlook日历开始或结束属性

2024-04-27 20:19:35 发布

您现在位置:Python中文网/ 问答频道 /正文

这段代码在python3.5.2中运行良好。在同一台机器上。在

在Python3.7.0中,当您试图让约会属性开始或结束时,它会挂起。 它只在第一个请求开始或结束时挂起。不会出现错误消息。在

在Windows10下测试,包括在命令控制台和Jupyter笔记本中。在

有什么建议或其他图书馆需要包括?在

import win32com.client
import datetime

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
calendar = outlook.GetDefaultFolder(9)
appointments = calendar.Items
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"

#This block restrict the time range. Doesn't change the hang up
begin = datetime.date(2018, 9, 1)  #year, month, day
end = datetime.date(2018, 10, 1)
print(f"Activities from: {begin}, to: {end}")
restriction = "[Start] >= '" + begin.strftime("%d/%m/%Y") + "' AND [End] <= '" +end.strftime("%d/%m/%Y") + "'"
print("restriction:", restriction)
restrictedItems = appointments.Restrict(restriction)

# The problem arise accessing as a unique item
appointment = restrictedItems[1]
print(appointment.Subject)
print(appointment.Organizer)
print(appointment.Start)
print(appointment.End)

# Also hangs up inside a loop of appointments
for appointment in restrictedItems:
    print(appointment.Subject)
    print(appointment.Organizer)
    print(appointment.Start)
    print(appointment.End)

Tags: importclientdatetimestartcalendarwin32comendappointment