Python:ValueError:microsecond在使用win32com时必须在0..999999中

2024-06-25 22:50:39 发布

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

我目前正在尝试使用python计算特定outlook文件夹中所有outlook邮件的提前期。一般来说,脚本运行良好,但在roundabout 2000封电子邮件之后,我收到以下错误(部分代码):

import win32com.client as win32
import pandas as pd
from datetime import date
import time

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI")

folder = outlook.Folders("example@example.com")
inbox = folder.Folders("Inbox")

messages = inbox.Items

df = pd.DataFrame()
index = 0
for msg in messages:
        if (msg.SenderEmailType != "EX"):
                print(str(msg.subject))
                print('Begin date:', msg.SentOn.strftime('%Y-%m-%d'))
                print('End date:',msg.LastModificationTime.strftime('%Y-%m-%d'))

                df.at[index, 'Subject'] = msg.subject
                df.at[index, 'Begin date'] = msg.SentOn.strftime('%Y-%m-%d')
                df.at[index, 'End date'] = msg.LastModificationTime.strftime('%Y-%m-%d')

我遇到了以下错误:

Traceback (most recent call last):
  File "C:\Users\USER\Desktop\MailCounts.py", line 24, in <module>
    print('End date:',msg.LastModificationTime.strftime('%Y-%m-%d'))
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
ValueError: microsecond must be in 0..999999

我试图通过选择特定的电子邮件并将其放入另一个outlook文件夹中,然后在上面循环来调试它。但是,它工作得很好,没有错误。所以它似乎是特定于文件夹的

我已经找到了一些关于错误和一般方法的答案。但就我所见,这个答案以前从未有过合适的答案。 提前谢谢


Tags: 答案inimport文件夹dfdateindex错误