How to connect Python program to Sharepoint onprem REST API using client id and secret provided?

Aashish Jain 11 Reputation points Microsoft Employee
2022-08-17T12:57:59.23+00:00

We are trying to connect share point 2013 onprem from python to to fetch file meta data details .

The following information was already provided to me:
I was thinking to do post call to get auth token but not able to figure out on which url , but I dint see any information about the connection and how to set the parameters there.

Client Id:
Client Secret:
Title:
App Domain:
Redirect URI:

THANKS

Microsoft 365 and Office SharePoint Development
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Aashish Jain 11 Reputation points Microsoft Employee
    2022-08-18T12:16:13.717+00:00

    @RaytheonXie_MSFT

    Getting error on the
    context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    AttributeError: 'NoneType' object has no attribute 'text'

    ---------------------------------------------------------------------------

    ConnectionResetError Traceback (most recent call last)
    /databricks/python/lib/python3.8/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    669 # Make the request on the httplib connection object.
    --> 670 httplib_response = self._make_request(
    671 conn,

    /databricks/python/lib/python3.8/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    380 try:
    --> 381 self._validate_conn(conn)
    382 except (SocketTimeout, BaseSSLError) as e:

    /databricks/python/lib/python3.8/site-packages/urllib3/connectionpool.py in _validate_conn(self, conn)
    977 if not getattr(conn, "sock", None): # AppEngine might not have .sock
    --> 978 conn.connect()
    979

    /databricks/python/lib/python3.8/site-packages/urllib3/connection.py in connect(self)
    361

    1 person found this answer helpful.

  2. Aashish Jain 11 Reputation points Microsoft Employee
    2022-09-05T16:41:42.443+00:00

    Thank you so much for the help and guidance on this.

    I have tried this method and didn't work for me as this share point is protect with ADFS and all external requests are going for authentication to that server . So i am working on the authentication process from ADFS with username and password.

    I will post the code here once i will have working piece for authentication using adfs for the sharepoint in python.

    Regards,
    Aashish

    1 person found this answer helpful.
    0 comments No comments

  3. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-08-18T02:26:52.81+00:00

    Hi anonymous userJain-7845
    You will need this library: https://pypi.org/project/Office365-REST-Python-Client/
    Here is the sample

     from office365.runtime.auth.authentication_context import AuthenticationContext  
     from office365.sharepoint.client_context import ClientContext  
     from office365.sharepoint.files.file import File  
          
     app_settings = {  
         'url': 'https://comapny.sharepoint.com/sites/spdev2/',  
         'client_id': 'aaaa-bbb-473a-a1b2-zzzzzfadfd',  
         'client_secret': 'Tteadsfdafdfasdff444gadfd=',  
     }  
          
     context_auth = AuthenticationContext(url=app_settings['url'])  
     context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])  
          
     ctx = ClientContext(app_settings['url'], context_auth)  
     web = ctx.web  
     ctx.load(web)  
     ctx.execute_query()  
     print("Web site title: {0}".format(web.properties['Title']))  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.