Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exchangelib.errors.ErrorAccessDenied: Not allowed to access Non IPM folder. #1290

Closed
PrajjawalBanati opened this issue Apr 4, 2024 · 23 comments

Comments

@PrajjawalBanati
Copy link

PrajjawalBanati commented Apr 4, 2024

Exchange lib is saying access denied with trying to access account.tois.children

I am using ExchangeLibHelper to fetch all the items from the respective folders from Top of Information Store Folder. '
It was working till yesterday.

To Reproduce

 folders = account.root.tois.children
for folder in folders:
      print(folder.name)

Expected behavior
I expected that it will traverse each folder from the folder collection object and give me the folder name

Log output
Exception stack trace

Traceback (most recent call last):
  File "exchangelib_helper.py", line 341, in get_mailbox_properties
    for folder in folders:
  File "lib\site-packages\exchangelib\folders\collections.py", line 50, in __iter__
    yield from self.folders
  File "lib\site-packages\cached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "lib\site-packages\exchangelib\folders\collections.py", line 44, in folders
    return list(self._folders)
  File "lib\site-packages\exchangelib\folders\roots.py", line 94, in get_children
    for f in self._folders_map.values():
  File "lib\site-packages\exchangelib\folders\roots.py", line 173, in _folders_map
    for f in SingleFolderQuerySet(account=self.account, folder=self).depth(
  File "lib\site-packages\exchangelib\folders\queryset.py", line 136, in _query
    for f, complex_f in zip(resolveable_folders, complex_folders):
  File "lib\site-packages\exchangelib\folders\collections.py", line 391, in get_folders
    yield from GetFolder(account=self.account).call(
  File "lib\site-packages\exchangelib\services\get_folder.py", line 40, in _elems_to_objs
    for folder, elem in zip(self.folders, elems):
  File "lib\site-packages\exchangelib\services\common.py", line 214, in _chunked_get_elements
    yield from self._get_elements(payload=payload_func(chunk, **kwargs))
  File "lib\site-packages\exchangelib\services\common.py", line 232, in _get_elements
    yield from self._response_generator(payload=payload)
  File "lib\site-packages\exchangelib\services\common.py", line 601, in _get_elements_in_response
    container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
  File "lib\site-packages\exchangelib\services\common.py", line 523, in _get_element_container
    raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
exchangelib.errors.ErrorAccessDenied: Not allowed to access Non IPM folder.
5836   5368   2024-04-04 11:44:53,158   ###        exchangelib_helper   get_mailbox_prop            592    ERROR     An error occurred while mailbox property for mailbox
Traceback (most recent call last):
  File "lib\site-packages\cached_property.py", line 70, in __get__
    return obj_dict[name]
KeyError: 'folders'

Additional context
Python -- 3.9
ExchangeLib -- 4.6.1

@albertaparicio-kriter
Copy link

We are facing this same issue on Exchange 5.2.0 with Python 3.11

It looks like a Microsoft 365 issue, rather than an issue with ExchangeLib

@Daniell-Green
Copy link

Same issue here.

Python 3.10
Exchanglib 4.8.0

@albertaparicio-kriter
Copy link

In our case, we have detected this error appears when moving a message to a different folder:

dst_folder = account.inbox / "foldername"
message.move(dst_folder)

This comment in issue 1288 suggests changing changing the single forward slash / to a double forward slash // for building folder paths.

We have tried this and it worked, so the code that caused the error now looks like this and it works:

dst_folder = account.inbox // "foldername" # Note the double slash in this line
message.move(dst_folder)

@Daniell-Green
Copy link

In our case, we have detected this error appears when moving a message to a different folder:

dst_folder = account.inbox / "foldername"
message.move(dst_folder)

This comment in issue 1288 suggests changing changing the single forward slash / to a double forward slash // for building folder paths.

We have tried this and it worked, so the code that caused the error now looks like this and it works:

dst_folder = account.inbox // "foldername" # Note the double slash in this line
message.move(dst_folder)

This solution worked for me. Thank you!

@ecederstrand
Copy link
Owner

Here's a possible fix for the ErrorAccessDenied issue: 7afd889

tommilligan pushed a commit to reinfer/exchangelib that referenced this issue Apr 4, 2024
@jcalero
Copy link
Contributor

jcalero commented Apr 4, 2024

Thanks a lot Erik, that has worked for us!

@vjean-atr
Copy link

Works for us too, we use the getFolderByName() function. Thanks!

@devseckoderz
Copy link

When will this update be available from pypi?

@SreeSonduri
Copy link

Hi need help for ErrorAccessDenied: Not allowed to access Non IPM folder tried double slash and also folder Collection. still getting this error "Unable to connect to exchange account. System will try to connect in the next run.
Not allowed to access Non IPM folder."

@xkobal
Copy link

xkobal commented Apr 5, 2024

We are facing the same issue. It would be great to release a new version if possible.

@pradeep-clex
Copy link

try like op.account.root // 'Top of Information Store' // 'Inbox' // to_move_folder)

Use double slash everywhere.

@SreeSonduri
Copy link

SreeSonduri commented Apr 5, 2024 via email

@pradeep-clex
Copy link

Yes try it, it worked for me. I had a similar issue this morning.

@SreeSonduri
Copy link

SreeSonduri commented Apr 5, 2024 via email

@devseckoderz
Copy link

devseckoderz commented Apr 5, 2024

Tried the fix mentioned above in get_folder.py, but get this error now:

"name 'create_shape_element' is not defined"

I am doing this for subfolders:

folder = account.inbox
all_folders = folder.glob('**/*')
for subfolders in all_folders:

@devseckoderz
Copy link

In our case, we have detected this error appears when moving a message to a different folder:

dst_folder = account.inbox / "foldername"
message.move(dst_folder)

This comment in issue 1288 suggests changing changing the single forward slash / to a double forward slash // for building folder paths.
We have tried this and it worked, so the code that caused the error now looks like this and it works:

dst_folder = account.inbox // "foldername" # Note the double slash in this line
message.move(dst_folder)

This solution worked for me. Thank you!

What if you are trying to traverse all subfolders and nested folders within Inbox/[SubFolders]?

@SreeSonduri
Copy link

Below is my code
inbox_folders = FolderCollection(account=account, folders=[account.inbox])

    for folder in inbox_folders.folders: 

        print(f'folder name::: {folder.name}')
    processed_folder = account.inbox // 'cost_auto_processed'

I get error as "No subfolder with name 'cost_auto_processed'"

Please let me know what could be the fix to get to to sub folders

@SreeSonduri
Copy link

SreeSonduri commented Apr 5, 2024 via email

@timschelle
Copy link

Is it possible that there are now also problems when creating?
If I run the following code example, I also get the error message: "Not allowed to access Non IPM folder"

f = Folder(parent=a.inbox, name="My New Folder")
f.save()

@ecederstrand
Copy link
Owner

ecederstrand commented Apr 8, 2024

The commit that closed this issue should fix the "ErrorAccessDenied: Not allowed to access Non IPM folder" issue for everyone. Please install from that commit until I can get a new version on PyPI. Only report here if that commit did not solve this specific issue for you.

@ecederstrand
Copy link
Owner

v5.2.1 is out now

@xkobal
Copy link

xkobal commented Apr 12, 2024

@ecederstrand Since the 5.2.1, this error has been replaced by:

exchangelib.errors.ErrorInvalidSchemaVersionForMailboxVersion: Tried versions ('Exchange2016', 'Exchange2015_SP1', 'Exchange2015', 'Exchange2013_SP1', 'Exchange2013', 'Exchange2010_SP2', 'Exchange2010_SP1', 'Exchange2010', 'Exchange2007_SP1', 'Exchange2007') but all were invalid

I don't understand why.

@ecederstrand
Copy link
Owner

That's very likely a different error. Please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests