OS (e.g. Windows 10 or macOS Sierra)
Windows 10
Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)
Python: 3.10.13
xlwings: 0.30.13
Excel: Microsoft® Excel® for Microsoft 365 MSO (Version 2302 Build 16.0.16130.20848) 32-bit
Describe your issue (incl. Traceback!)
This is in reference to issue #1829 / pull request #1871. I have multiple shared (sub)folders from mutiple channels of a MS Business Team (i.e. hosted as multiple subfolders of a SharePoint). E.g. these two:
[HKEY_CURRENT_USER\SOFTWARE\SyncEngines\Providers\OneDrive\63d95dea23614820b35cee35dd73d8c6+1]
"MountPoint"="C:\\Users\\Robert\\Abc\\FO Migration - Financial Risk - 02_TEST"
"UrlNamespace"="https://abc.sharepoint.com/sites/FOMigration-FinancialRisk/Shared Documents/"
[HKEY_CURRENT_USER\SOFTWARE\SyncEngines\Providers\OneDrive\00d8a9b4cc2549fd8674fb3ac5d0ad38+1]
"MountPoint"="C:\\Users\\Robert\\Abc\\FO Migration - Financial Risk - 03_TEST"
"UrlNamespace"="https://abc.sharepoint.com/sites/FOMigration-FinancialRisk/Shared Documents/"
Since get_url_to_mount() in utils.py is collecting the mount points by urls, the entries are overwritten and only the last one prevails.
Consider now e.g. the file https://abc.sharepoint.com/sites/FOMigration-FinancialRisk/Shared Documents/02_TEST/test.xlsx, locally synched to C:\Users\Robert\Abc\FO Migration - Financial Risk - 02_TEST.
In fullname_url_to_local_path(), the check in line 577 is passed for MountPoint 03_TEST because the check only considers the startswith(url_namespace) even though the file is in 02_TEST. Clearly local_path.is_file(), thus, returns False and, ultimately, the subsequent search_local_sharepoint_path() fails with xlwings.XlwingsError("Couldn't find your SharePoint file locally, see: xlwings.org/error") (line 744).
# SharePoint Online & On-Premises (Windows registry)
url_to_mount = get_url_to_mount()
for url_namespace, mount_point in url_to_mount.items():
if url.startswith(url_namespace):
local_path = Path(mount_point) / url[len(url_namespace) :]
if local_path.is_file():
return str(local_path)
else:
return search_local_sharepoint_path(
url, mount_point, sharepoint_config, sharepoint_config_name
)
# SharePoint Online & On-Premises (default top level mapping)
pattern = re.compile(r"https?://[^/]*/sites/([^/]*)/([^/]*)/(.*)")
match = pattern.match(url)
# We're trying to derive the SharePoint root path
# from the OneDriveCommercial path, if it exists
root = sharepoint_config or (
os.getenv("OneDriveCommercial").replace("OneDrive - ", "")
if os.getenv("OneDriveCommercial")
else None
)
Unfortunately this cannot be avoided by creating a xlwings.conf sheet with SHAREPOINT_WIN because the latter is only checked AFTER the above check and, due to the raised error, is never executed. So for me a simple solution was to comment out the entire for loop above, but this is not a general solution.
I would see the following opportunities to fix the error:
- Store the MountPoint / UrlNamespace pairs in a way that entries are not overwritten and amend the if-clause from startswith() to a more detailed check.
- Not raise an error in
search_local_sharepoint_path() in case there the file cannot be found and/or catch this error in fullname_url_to_local_path
- Put the check for
SHAREPOINT_WIN in xlwings.conf earlier in fullname_url_to_local_path(), such that the loop is never executed.
Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)
cf. above
OS (e.g. Windows 10 or macOS Sierra)
Windows 10
Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)
Python: 3.10.13
xlwings: 0.30.13
Excel: Microsoft® Excel® for Microsoft 365 MSO (Version 2302 Build 16.0.16130.20848) 32-bit
Describe your issue (incl. Traceback!)
This is in reference to issue #1829 / pull request #1871. I have multiple shared (sub)folders from mutiple channels of a MS Business Team (i.e. hosted as multiple subfolders of a SharePoint). E.g. these two:
Since
get_url_to_mount()inutils.pyis collecting the mount points by urls, the entries are overwritten and only the last one prevails.Consider now e.g. the file
https://abc.sharepoint.com/sites/FOMigration-FinancialRisk/Shared Documents/02_TEST/test.xlsx, locally synched toC:\Users\Robert\Abc\FO Migration - Financial Risk - 02_TEST.In
fullname_url_to_local_path(), the check in line 577 is passed for MountPoint 03_TEST because the check only considers the startswith(url_namespace) even though the file is in 02_TEST. Clearlylocal_path.is_file(), thus, returnsFalseand, ultimately, the subsequentsearch_local_sharepoint_path()fails withxlwings.XlwingsError("Couldn't find your SharePoint file locally, see: xlwings.org/error")(line 744).Unfortunately this cannot be avoided by creating a
xlwings.confsheet withSHAREPOINT_WINbecause the latter is only checked AFTER the above check and, due to the raised error, is never executed. So for me a simple solution was to comment out the entire for loop above, but this is not a general solution.I would see the following opportunities to fix the error:
search_local_sharepoint_path()in case there the file cannot be found and/or catch this error infullname_url_to_local_pathSHAREPOINT_WINinxlwings.confearlier infullname_url_to_local_path(), such that the loop is never executed.Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)
cf. above