我有这个代码:
import win32com.client
import pythoncom
import datetime
def saveMeeting(start, end, subject, location, attachments, recipients):
outlook = win32com.client.Dispatch("Outlook.Application", pythoncom.CoInitialize())
ns = outlook.GetNamespace("MAPI")
session = ns.Session
## Find the accounts that are of exchange type
acc = []
for account in session.Accounts:
if account.AccountType == 0: #0 - outlookExchange, 1 - outlookIMAP, 2 - outlookPop3
#print(account)
acc.append(account)
appointment = outlook.CreateItem(1) #1 - AppointmentItem
# Fill in the data needed
appointment.SendUsingAccount = acc
appointment.Start = datetime.datetime.strptime(start, "%Y-%m-%d %H:%M:%S") #yyyy-MM-dd hh:mm:ss
appointment.StartTimeZone = outlook.TimeZones("Central Standard Time")
appointment.End = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M:%S") #yyyy-MM-dd hh:mm:ss
appointment.EndTimeZone = outlook.TimeZones("Central Standard Time")
appointment.Subject = f"HOLDER-{subject}"
appointment.Location = location
appointment.MeetingStatus = 1
if attachments != '':
appointment.Attachments.Add(attachments)
recipients = filter(None, recipients)
for recipient in recipients:
r = appointment.Recipients.Add(recipient)
r.Resolve()
appointment.Save()
# Only use .Display() if using tkinter
appointment.Display()
saveMeeting("2022-03-02 14:00:00", "2022-03-02 14:30:00", "Subject of the Meeting","Location", "", ["altisjessienino18@gmail.com", "ajn_dulay@smcm.edu.ph"])
但是,它只是给了我这个错误。
Traceback (most recent call last):
File "C:\Users\user\Desktop\Project\createInvite.py", line 100, in <module>
saveMeeting("2022-03-02 14:00:00", "2022-03-02 14:30:00", "Subject of the Meeting","Location", "", ["user1@gmail.com", "user2@smcm.edu.ph"])
File "C:\Users\user\Desktop\Project\createInvite.py", line 42, in saveMeeting
appointment.End = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M:%S") #yyyy-MM-dd hh:mm:ss
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\win32com\client\dynamic.py", line 686, in __setattr__
self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The object does not support this method.', None, 0, -2147352567), None)
我正在尝试使用 pywin32 和 python 创建约会。但问题是有时它可以工作,有时它不喜欢这里的代码,似乎有一个我看不到或隐藏在某个地方的问题。这里的主要问题是我正在尝试解决日期问题(它变成了 UTC+6 而不是 UTC-6)。