I am having problems trying to POST a file to Sharepoint using WinHTTPRequest and Python.
From the MS Docs, it has the sample code:
url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/Add(url='file name', overwrite=true) method: POST body: contents of binary file headers: Authorization: "Bearer " + accessToken X-RequestDigest: form digest value content-type: "application/json;odata=verbose" content-length:length of post body
But I am not sure how should I insert the "body" part in the above code, I don't see a method in the Docs to change the body. And WinHTTPReuqest is the only method I can use since I don't have access to other packages and the content type seems always be in the XML format.
import win32com.client
request = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
request.SetAutoLogonPolicy(0)
request.Open('POST', url, False)
request.SetRequestHeader("content-type","application/XML")
# How Do I insert the file I want to upload here?
request.Send()