I am trying to download file from SharePoint using below code

url ='https://site_url/_api/web/GetFileByServerRelativeUrl("/PraveenTest/Test/file_name")/$value'
headers = {Authorization: "Bearer"  + accessToken}
response = requests.get(url=url, headers=headers)

response is 400.

Why exactly I am facing this issue?

  • Can you please post the complete code you are using? Also, check the relative path you provided is correct or not? Aug 13, 2019 at 10:23

2 Answers 2


Below is the complete example of how to get the file from SharePoint:

var hostweburl = decodeURIComponent(getParameterByName('SPHostUrl'));
var appweburl = decodeURIComponent(getParameterByName('SPAppWebUrl'));

var fileContentUrl = "_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('/site/library/madcow.xlsx')/$value?@target='" + hostweburl + "'";

var executor = new SP.RequestExecutor(appweburl);
var info = {
    url: fileContentUrl,
    method: "GET",
    binaryStringResponseBody: true,
    success: function (data) {
        //binary data available in data.body
        var result = data.body;
    error: function (err) {

Source: How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013.

You can also check below documentation for Complete basic operations using SharePoint REST endpoints:

Complete basic operations using SharePoint REST endpoints.


There is also this method.

https://siteurl/_api/web/GetFolderByServerRelativeUrl('List or Library Name/')/Files('File Name')/

The following example shows how to retrieve a file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.