Problem:
The problem is that Sharepoint is expecting binary data from your request. But you are sending some batches of data. When you make a request, the python request library automatically adds to the header
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryNTIFeyYj307EY4HV
As an example, try sending a .txt file with the text "fcvsdcvsd". When you upload this file to your Sharepoint site, you will receive another file. This is what I got in the Sharepoint file repository when I downloaded this file:
------WebKitFormBoundaryCGYE31vAG1tfvbzV
Content-Disposition: form-data; name="fileUpload1"; filename="testtest.txt"
Content-Type: text/plain
fcvsdcvsd
------WebKitFormBoundaryCGYE31vAG1tfvbzV--
In your case, these lines are also added to your file. When Excel tries to open this file, it finds these lines and stops reading because the file is damaged.
:
, .
headers = {"accept": "application/json;odata=verbose",
"X-RequestDigest": token,
"content-type": "application/x-www-urlencoded; charset=UTF-8"}
with open(local_path, "rb") as read_file:
content = read_file.read()
r = requests.post(url + "getFolderByServerRelativeUrl('" + location + "')/files/add(overwrite=true,url='" + filename + "')",
data=content, auth=auth, headers=headers)
, ( "" ) ( " " ), "application/x-www-urlencoded; charset = UTF-8"
txt ,
fcvsdcvsd
URL- - URL-, Sharepoint (?).
- ,
"X-RequestDigest": , Sharepoint.