3

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?

Vityata
  • 42,633
  • 8
  • 55
  • 100
  • Are you using two-factor authentication for SharePoint access? The shareplum does not seem to support 2FA currently. The workaround could be using an "app password". There is also a CLI for microsoft 365, https://pnp.github.io/cli-microsoft365/cmd/spo/file/file-add/ – Nikolay Jan 22 '23 at 15:19
  • Please, check if this thread is helpfull for you: [SecureAuth cause - ShareplumRequestError: Shareplum HTTP Post Failed : 403 Client Error: Forbidden for url](https://stackoverflow.com/questions/68390250/secureauth-cause-shareplumrequesterror-shareplum-http-post-failed-403-clien/68893435#68893435) – Antonio Leonardo Jan 24 '23 at 20:31
  • @AntonioLeonardo - thanks, but it should be with LDAP. – Vityata Jan 25 '23 at 08:58
  • @Nikolay - Thanks. No, I am w/o the two-factor authentication. Just with LDAP. – Vityata Jan 25 '23 at 08:59
  • I see. Are you running on Linux platform and not using Azure AD or Microsoft Active Directory? AFAIK SharePoint Online authenticates users using Azure AD, do you have some sort of connector for your LDAP server configured? Can you open the SharePoint site in a browser? It looks like this may be more of an administration issue. Sorry, can't help here. – Nikolay Jan 25 '23 at 13:48
  • @Nikolay - 1. Running on Windows. 2. No idea about any sort of connector configured. 3. Yes. Thanks for trying anyway :) – Vityata Jan 25 '23 at 14:04
  • Hmm, just to clearify, why are you talking about LDAP on windows? Maybe you mean NTLM (built-in windows active directory authentication)? – Nikolay Jan 25 '23 at 14:52
  • @Nikolay - I am not a lot of an admin guy, I just know that it is called LDAP id and its idea is, that I can enter specific sites and places, without providing username and password, but it takes it from my Windows one. It could be NTLM, but I have seen it written LDAP. I have tried also w/o username and password, still did not work. – Vityata Jan 25 '23 at 15:24
  • I see. It looks like you are using built-in windows authentication in your organization and have it synced to Microsoft 365. You may have better luck using this python client, it may support this "mixed" authentication as well: https://pypi.org/project/Office365-REST-Python-Client – Nikolay Jan 25 '23 at 17:12

0 Answers0