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

ServerRelativeUrl value is not encoded #918

Closed
CTPassion opened this issue Dec 5, 2024 · 0 comments
Closed

ServerRelativeUrl value is not encoded #918

CTPassion opened this issue Dec 5, 2024 · 0 comments
Labels

Comments

@CTPassion
Copy link

IMO a bug.

Using the office365.sharepoint.files.file:open_binary method (or any method that calls this, like .read()) will raise an exception if the file name contains a character that should be encoded to make a safe URL.

e.g. file name "#123 Report" fails because of the # left in the URL by open_binary().

Suggestion:

  • Either the file.properties["ServerRelativeUrl"] should be encoded safely at point of ingestion
  • Or the URLs should be encoded before execution:
    
    from urllib.parse import quote
    
    @staticmethod
    def open_binary(context, server_relative_url):
        """
        Returns the file object located at the specified server-relative URL.
    
        :type context: office365.sharepoint.client_context.ClientContext
        :type server_relative_url: str
        :return Response
        """
        url = r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format(
            context.service_root_url(), server_relative_url
        )
        request = RequestOptions(quote(url, safe=':/'))    <----- ADDED quote HERE
        request.method = HttpMethod.Get
        response = context.pending_request().execute_request_direct(request)
        return response
        ```
    
vgrem added a commit that referenced this issue Dec 5, 2024
#918 - Add urllib parse quote encoding to the URL
@vgrem vgrem added the bug label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants