MAPI未定义

2024-10-02 16:25:58 发布

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

我有一个运行良好的代码3个月,直到现在我已经开始看到错误,不知道什么需要修改

我最初的代码是:

import pandas as pd
import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
root_folder = namespace.Folders.Item(3)
subfolder = root_folder.Folders['Inbox'].Folders['Daily Process']
messages = subfolder.Items
message = messages.GetFirst()
subj_line = message.subject

然而,我得到以下错误

com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The attempted operation failed.  An object could not be found.', None, 0, -2147221233), None)

我把代码分解了,似乎不再定义名称“MAPI”

import pandas as pd
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
your_folder = namespace.Folders['Inbox'].Folders['Daily Process']
for message in your_folder.Items:
    print(message.Subject)

这让我

name 'mapi' is not defined

Tags: 代码importclientmessagepandasas错误folder