Skip to main content
 首页 » 编程设计

Python 3.7 挂起获取约会项目的 Outlook 日历开始或结束属性

2025年05月04日10lovecherry

此代码在 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) 

请您参考如下方法:

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