pythonexchangelib

Not allowed to access Non IPM folder


I've been using exchangelib library in python for a long time now to access emails in an email account. It's been working amazing. Out of the blue today, I get an error saying,

KeyError: 'folders' 
During handling of the above exception, another exception occured:
exchangelib.errors.ErrorAccessDenied: Not allowed to access Non IPM folder.

The line of code this is happening on is right here.

msg_folder= my_account.root / 'Top of Information Store' / 'my_subfolder'

Like I mentioned, this has been working great for over a year now. Double checked that access for the microsoft application is correct, and it is. It also looks like the latest release of exchangelib was 3/8/24 and it's been working since then, so it can't be that.

The other weird thing, is a separate script is able to access messages in the inbox, it's just this sibling folder to the inbox that is throwing the error.

I'm not finding anything on this error though. Any ideas on how to fix this?


Solution

  • This is caused by a recent change in O365. We may be able to find a fix for it in exchangelib. Until then, a workaround is to navigate to folders using double slashes:

    msg_folder = my_account.root // 'Top of Information Store' // 'my_subfolder'
    

    This works by not collecting the full folder hierarchy first and navigating the client-side folder cache, but rather asking the server for the specific child folder each time we reach a new // level.

    UPDATE: fix provided in https://github.com/ecederstrand/exchangelib/issues/1290