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

Cannot download files with an apostrophe < ' > in path using file.read() #884

Open
le-codeur-rapide opened this issue Aug 6, 2024 · 0 comments

Comments

@le-codeur-rapide
Copy link

Hi I was using the library to download some files from sharepoint using file.read()

`
for _, row in tqdm.tqdm(df.iterrows()):
file_url = row['Relative URL']
local_path = os.path.join(local_folder, row['Relative URL'].lstrip('/'))

    # Create the local directory if it doesn't exist
    os.makedirs(os.path.dirname(local_path), exist_ok=True)

    # Get the file from SharePoint
    file = ctx.web.get_file_by_server_relative_path(str(file_url))
    ctx.load(file)
    ctx.execute_query()

    # Save the file locally
    with open(local_path, 'wb') as local_file:
        file.read()  

`

I had issues with files that had an appostrophe ex: < macdonald's.pdf > because the "'" is not encoded in the final url

Replacing file.read() by file.download(local_file).execute_query() It is working fine.

Is it expected behaviour ? is file.read() not supposed to handle the appostrophe also ?

Thank you for your answer !

@le-codeur-rapide le-codeur-rapide changed the title Difference between file.read() and file.download(local_file).execute_query() in how url are encoded Cannot download files with an apostrophe < ' > in path using file.read() Aug 6, 2024
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

1 participant