'Cannot open excel file on Sharepoint uploaded by Python

I couldn't open excel file on sharepoint(wrong file extension-> screenshot on below). I created code base on Postman API and then translated it to Python-Requests by code snippet. It is interesting because I did the same for csv file and everything works fine. My current code is here:

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 xxxxx',
  'Accept': 'application/json;odata=verbose',
  'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}

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

print(response.text)

My SP after code execution:

Error during openning uploaded file:



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source