Problem
When attempting to connect to SharePoint from a Databricks notebook, you encounter a 404 'Not Found' error, even though you have the correct permissions and a valid folder path.
This error specifically occurs when trying to access a file from SharePoint, for example, https://xxxx.sharepoint.com/<path-to-the-file>
, suggesting that the issue is more likely related to connectivity or URL formatting rather than permissions.
Cause
Your code uses URL-encoded characters (for example, %20 for spaces) in the file path.
While URL encoding is typically correct for web URLs, in the specific case of SharePoint integration with Databricks, the SharePoint API expects native filesystem-style paths rather than web-encoded URLs when accessing documents through the File.open_binary
method.
Solution
- Remove URL encoding for spaces (%20) from the path.
- Use regular spaces in the file path.
- Maintain the relative path structure as is.
Example
The following code shows an example of %20 for spaces, which causes the error.
response = File.open_binary(ctx, "/sites/itfinance/Shared%20Documents/Evolve%20IT%20Finance/Database/...")
The corrected code uses spaces instead of of %20s.
pythonCopyresponse = File.open_binary(ctx, "/sites/itfinance/Shared Documents/Evolve IT Finance/Database/...")