Authentication error when accessing Microsoft SharePoint - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Authentication error when accessing Microsoft SharePoint (/thread-27410.html) |
Authentication error when accessing Microsoft SharePoint - klllmmm - Jun-05-2020 Hi all, I'm trying to upload a file from my computer to my Microsoft SharePoint site using a python script. I have a SharePoint site created through free MS teams org. But I got an "Exception error" in the "authcookie" line. My site_name is like 'https://myorg.sharepoint.com' and base_path is like 'Myorg-channel' (ie https://myorg.sharepoint.com/sites/Myorg-channel) And I'm using MS Team admin user email and password who has the access to this channel. Code I tried- import requests from shareplum import Office365 username = '[email protected]' password = 'adminPassword' site_name = 'https://myorg.sharepoint.com' base_path = 'Myorg-channel' # Obtain auth cookie authcookie = Office365(base_path, username=username, password=password).GetCookies()Error message- Appreciate it if someone can help to rectify this error.
RE: Authentication error when accessing Microsoft SharePoint - nuffink - Jun-05-2020 I am not sure if this will help, but my dealings with sharepoint has meant it has used NTLM as an authorisation protocol for which there is a python package on PyPi, you can also see if the connection is correct via postman package prior to attempting to replicate in python. RE: Authentication error when accessing Microsoft SharePoint - klllmmm - Jun-10-2020 I tried requests_ntlm package, but it didn't work. import requests from requests_ntlm import HttpNtlmAuth requests.get("https://myorg.sharepoint.com", auth=HttpNtlmAuth("myorg"+"\\"+'[email protected]','adminPassword')) Also, I tried using Sharepoint package, but not getting the access to my SharePoint sitefrom sharepoint import SharePointSite, basic_auth_opener server_url = "https://myorg.sharepoint.com/" site_url = server_url + "sites/Myorg-channel/" opener = basic_auth_opener(server_url, '[email protected]','adminPassword') site = SharePointSite(site_url, opener) for sp_list in site.lists: print(sp_list.id)
RE: Authentication error when accessing Microsoft SharePoint - nuffink - Jun-10-2020 Hi OK, then i would suggest before you carry on with python you install postman - link is here - its basically a "REST" client if you haven't used but there is the ability in there to use the NTLM protocol so at least with your user / domain / password combo you can see if you can get it to work form there, this would at least prove it is able to accept you requests. NTLM tbh is pants! it takes 3 request response combinations to authenticate 1. request to ntlm (sharepoint in this case) 2. if authenticated then an authentication "token" is returned in the http headers 3. request is sent with this token and whatever the request body is asking sharepoint to do - fetch docs etc You can set up the same in SOAPUI and see the aforementoned transations, but I prefer Postman Once you have established that working then apply the similar to python, especially if the packages you are using are either complex or you can't ascertain what they are doing, it might give some pointers as to where the error is. If you need additional help with the postman set up am happy to help |