Search code examples
pythonoutlookpywin32

Win32 error: Object has no attribute 'folders'


I'm getting an error whit Outlook .folders with Win32 using python.

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.folders("X").folders("X").folders("X")

Error:

Traceback (most recent call last): File "X", line 34, in inbox = outlook.folders("X").folders("X").folders("X") File "C:\X\X\X\X\X\Python\Python38\lib\site-packages\win32com\client__init__.py", line 473, in getattr raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) AttributeError: '' object has no attribute 'folders'

It is strange because the script works sometimes on my machine and seems to work with no issues on my collegues machines.

I'm running:

  • Python 3.8.1
  • pywin32 227

UPDATE: I noticed I'm able to run the script once when I restart my computer. The error shows up on the second attempt.


Solution

  • The script in the error message does not match the script you posted above. Error message:

    inbox = accounts.folders("X").folders("X").folders("X")

    your script:

    inbox = outlook.folders("X").folders("X").folders("X")

    Also, try to use Folders.Item function rather than relying on the default property:

    inbox = outlook.folders.Item("X").folders.Item("X").folders.Item("X")