I am trying to upload an Excel file to SharePoint, using the code I found here, but so far, I cannot manage to make it work with my LDAP account. Getting this error:
raise ShareplumRequestError("Shareplum HTTP Post Failed", err)
shareplum.errors.ShareplumRequestError: Shareplum HTTP Post Failed :
HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001B24A126B08>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
with this code:
from shareplum import Office365
from shareplum import Site
from shareplum.site import Version
def main():
sp = r"//foo.sharepoint.com/sites/foobarwiki/Shared Documents/SourceExcelFile.xlsx"
cp = r"C:\Users\Git\SourceExcelFile.xlsx"
authcookie = Office365('https://foo.sharepoint.com', username='un', password='pwd').GetCookies()
site = Site(r'https://foo.sharepoint.com/sites/foobarwiki/', version=Version.v365, authcookie=authcookie);
folder = site.Folder('Shared Documents/foobarbar/')
with open(cp, mode='rb') as file:
fileContent = file.read()
folder.upload_file(fileContent, "myfile.txt")
print("Done!")
if __name__ == "__main__":
main()
As this can be considered an xy question, in the meantime, I tried simply using shutil.copy(cp, sp)
and .copy2
, as it should be ok and I am quite ok to access the SharePoint with other ways, but still no success there as I guess shutil
does not like SharePoint a lot.
Any ideas?