Skip to content

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

Open
@le-codeur-rapide

Description

@le-codeur-rapide

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions