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

Requests MissingSchema Error when downloading file #271

Closed
etiennecelery opened this issue Oct 2, 2020 · 5 comments
Closed

Requests MissingSchema Error when downloading file #271

etiennecelery opened this issue Oct 2, 2020 · 5 comments

Comments

@etiennecelery
Copy link

Hi!

I'm having trouble downloading a file from SharePoint using the latest 2.2.1 version of Office365. When I try to download a file a "MissingSchema" Error from the requests module appears. I don't know what happened, if I go back to version 2.1.5 the code runs fine. Thank you very much and I appreciate the hard work in this module; super useful!

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File

def auth(username, password):
    ctx_auth = AuthenticationContext(url)
    if ctx_auth.acquire_token_for_user(username, password):
      ctx = ClientContext(url, ctx_auth)
      return ctx

ctx = auth(username, password)
response = File.open_binary(ctx, relative_url)

Error:
MissingSchema: Invalid URL "<bound method ClientContext.service_root_url of <office365.sharepoint.client_context.ClientContext object at 0x7fb4e44c3d90>>web/getfilebyserverrelativeurl('MYRELATIVEURL')/\\$value": No schema supplied. Perhaps you meant http://<bound method ClientContext.service_root_url of <office365.sharepoint.client_context.ClientContext object at 0x7fb4e44c3d90>>web/getfilebyserverrelativeurl('MYRELATIVEURL')/\$value?

Using MacOS,
Office365 2.2.1,
Python 3.8.3,
requests 2.2.4

@vgrem vgrem added the question label Oct 3, 2020
@efremovd
Copy link

efremovd commented Oct 9, 2020

There is a bug in 2.2.1 version you either need to use latest from git or fix it manually in your installation here https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint/files/file.py#L275

Note that in you version ctx.service_root_url is a property but should be a method ctx.service_root_url()

@vgrem vgrem added the bug label Oct 9, 2020
@vgrem
Copy link
Owner

vgrem commented Oct 9, 2020

Thank you @efremovd and @etiennecelery for catching and pinpoint it, indeed it is a bug and is encountered in version 2.2.1 due to refactoring service_root_url property to method.

As was mentioned, the latest version available from GitHub resolves this issue:

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

Alternatively, the file could be downloaded as demonstrated below:

file_url = '{server-relative-path-to-download}'
with open(download_path, "wb") as local_file:
    file = ctx.web.get_file_by_server_relative_url(file_url).download(local_file).execute_query()

@etiennecelery
Copy link
Author

Thank you!! Great work

@vgrem
Copy link
Owner

vgrem commented Nov 8, 2020

Closing this one since has been resolved and 2.2.2 version has been released.

@vgrem vgrem closed this as completed Nov 8, 2020
@prabhuSub
Copy link

Works like a charm. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants