Upload excel file to sharepoint

Hi Guys,

I created code in Postman which upload xlsx file to sharepoint and it works very good, but my main goal is create code in python. For this I used Code snippet function and I chose Python - Requests . I can execute this code by I couldn’t open this file on sharepoint(screenshot on below). It is interesting because I did the same for csv file and everything works fine. I think that maybe there is connected to proper ‘Content-Type’? I believe that someone help me with this tricky issue! :slight_smile:

My code(Python - Requests in Code Snippet):

import requests

url = "https://xxx.sharepoint.com/sites/RW-RUS-ControllingRUS-Budget-template/_api/web/GetFolderByServerRelativeUrl('Shared Documents/RockBI Alert')/Files/add(url='Chains2.xlsx',overwrite=true)"

payload="<file contents here>"

headers = {

  'Host': 'xxx.sharepoint.com',

  'Authorization': 'Bearer xxxx',

  'Accept': 'application/json;odata=verbose',

  'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'


response = requests.request("POST", url, headers=headers, data=payload)


On below you can find my screenshot with sharepoint error: