首页 > 解决方案 > Python 3.7 挂起获取约会项目的 Outlook 日历开始或结束属性

问题描述

此代码在 Python 3.5.2 中运行良好。在同一台机器上。

在 Python 3.7.0 中,当您尝试获取约会属性开始或结束时,它会挂起。它仅在第一次请求开始或结束时挂断。不会出现错误消息。

在 Windows 10 下,在命令控制台和 Jupyter Notebook 中进行了测试。

需要包含任何建议或其他库吗?

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)

标签: pythonpython-3.xoutlookcalendar

解决方案


对于 Python 3.7.0,您需要使用 pywin32 224(今天的最后一个版本)。感谢 Mark Hammond 生成了这个新版本的 pywin32 来解决这个问题。


推荐阅读