Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created August 4, 2025 01:27
Show Gist options
  • Select an option

  • Save KyMidd/2369b685b5ef52f2d7a7ec96f2051983 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/2369b685b5ef52f2d7a7ec96f2051983 to your computer and use it in GitHub Desktop.
def download_file_for_user(file_name, file_url, headers):
try:
if ".sharepoint.com/sites/" in file_url:
# ...
# Try to access the file after normalizing the path
normalized_path = unicodedata.normalize("NFKC", file_relative_path_raw).replace('\u202f', ' ')
if normalized_path != file_relative_path_raw:
normalized_encoded = urllib.parse.quote(normalized_path, safe="/")
graph_url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{drive_id}/root:/{normalized_encoded}:/content"
print(f"🟢 Attempting normalized path download URL: {graph_url}")
resp = requests.get(graph_url, headers=headers)
if resp.status_code == 200:
print(f"🟢 Download succeeded from SharePoint site using normalized path: {graph_url}")
return resp.content
else:
print(f"🚫 Normalized path download failed: {resp.status_code} - {resp.text}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment