gpt4 book ai didi

python - 类型错误 : '_Folders' object is not callable

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:41 24 4
gpt4 key购买 nike

我正在使用 win32.client 并尝试操作电子邮件正文。

今天可以正常工作,但我认为在测试时我可能破坏了 Outlook!当我尝试调用 _Folders 对象的索引时,出现类型错误,表明它无法调用。

我使用索引进入我的嵌套文件夹。这一直有效到今晚,我没有更改任何代码。

import win32com.client
import urllib.parse
import webbrowser
from pyshorteners import Shortener

application = win32com.client.Dispatch('Outlook.Application')
namespace = application.GetNamespace('MAPI')

# 6 is the number for the main inbox
inbox_folder = namespace.GetDefaultFolder(6)

# had to create multiple objects of subfolders to get to specific directory
inbox = inbox_folder.Folders
mobile_folder = inbox(3)
mobile_folder_directory = mobile_folder.Folders
mobile_script_folder = mobile_folder_directory(2)

# using Items method to parse specific email files within the folder
messages = inbox_folder.Items

我收到此错误:

File "mail1.py", line 10, in mobile_folder = inbox_folders(3) TypeError: '_Folders' object is not callable

我正在摆弄其他代码,试图监视我的收件箱中的新邮件。

我在另一个文件中运行了一些代码,并进行了一些修改以匹配我的收件箱

import ctypes # for the VM_QUIT to stop PumpMessage()
import pythoncom
import win32com.client
import sys


# outlook config
SHARED_MAILBOX = "Your Mailbox Name"

# get the outlook instance and inbox folder
session = win32com.client.Dispatch("Outlook.Application").Session
user = session.CreateRecipient(SHARED_MAILBOX)
shared_inbox = session.GetSharedDefaultFolder(user, 6).Items # 6 is Inbox


class HandlerClass(object):

def OnItemAdd(self, item):
print("New item added in shared mailbox")
if item.Class == 43:
print("The item is an email!")


outlook = win32com.client.DispatchWithEvents(shared_inbox, HandlerClass)


def main():
print("Starting up Outlook watcher")
pythoncom.PumpMessages()


if __name__ == "__main__":
try:
status = main()
sys.exit(status)
except KeyboardInterrupt:
print("Terminating program..")
ctypes.windll.user32.PostQuitMessage(0)
sys.exit()

我怀疑它改变了 Outlook 版本的某些内容。

我还收到消息说 MAPIFolder 对象不可调用。我的研究表明这是一个旧的、不受支持的 Outlook 协议(protocol)。

当我尝试为文件夹建立索引时,这里有更多数据:

>>> inbox_folder
<win32com.gen_py.Microsoft Outlook 16.0 Object Library.MAPIFolder instance at 0x12191504>
>>> inbox = inbox_folder.Folders
>>> inbox
<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Folders instance at 0x46668848>
>>> inbox(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '_Folders' object is not callable

最佳答案

我仍然不知道是什么破坏了它,但事实证明按索引搜索文件夹不再起作用。

解决方案现在按文件夹名称搜索:

inbox_folder = namespace.GetDefaultFolder(6) 

# had to create multiple objects of subfolders to get to specific directory
inbox = inbox_folder.Folders
mobile_folder = inbox["Mobile"]
mobile_script_folder = mobile_folder.Folders["Mobile_4_4_Alpha"]

不知道为什么它修复了它,但它确实修复了。耶!

关于python - 类型错误 : '_Folders' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55980099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com