Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Read sharepoint list items using Python

$
0
0

I want to read the sharepoint list items using graph api. I have this code which allows me to get a list of SharePoint Lists using a access token.

from pypac import PACSessionsession = PACSession()headers = {'authorization': f'Bearer {access_token}',}response = session.request("GET",'https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com:/sites/xxx/xxx/BTADMCA:/lists?select=id,name',    headers=headers,)response.json()

I have two issue with this is that I am only getting the list ids but not able to retrieve the rows in the list the second issue I have is that I am not how to get a new access token from graph api. I have MFA enabled on my account and I dont have client secret for sharepoint because I dont have admin rights. I have to login using a code from my phone and approve login in order to sign in

Can you please help in getting the graph access token and reading rows from the list?

Sharepoint link https://xxxx.sharepoint.com/sites/xxx/xxxx/BTADMCA/Lists/Central/AllItems.aspx

I tried the following code to get the access code:

import adalauthority_url = "https://login.microsoftonline.com/common"client_id = "de8bc8b5-d9f9-48b1-a8ad-b748da725064"auth_context = adal.AuthenticationContext(authority_url)# Initiate device code flowdevice_code = auth_context.acquire_user_code("https://graph.microsoft.com/", client_id)print(device_code['message'])# Poll for token using device codetoken_response = auth_context.acquire_token_with_device_code("https://graph.microsoft.com/", device_code, client_id)access_token = token_response["accessToken"]print("Access token acquired successfully:", access_token)

I get the following error:

AdalError                                 Traceback (most recent call last)<ipython-input-24-afa3aa1fa6be> in <module>     11      12 # Poll for token using device code---> 13 token_response = auth_context.acquire_token_with_device_code("https://graph.microsoft.com/", device_code, client_id)     14      15 access_token = token_response["accessToken"]c:\ProgramData\python36\lib\site-packages\adal\authentication_context.py in acquire_token_with_device_code(self, resource, user_code_info, client_id)    309             return token    310 --> 311         return self._acquire_token(token_func, user_code_info.get('correlation_id', None))    312     313     def cancel_request_to_get_token_with_device_code(self, user_code_info):c:\ProgramData\python36\lib\site-packages\adal\authentication_context.py in _acquire_token(self, token_func, correlation_id)    126             correlation_id or self.correlation_id, self._call_context.get('enable_pii', False))    127         self.authority.validate(self._call_context)--> 128         return token_func(self)    129     130     def acquire_token(self, resource, user_id, client_id):c:\ProgramData\python36\lib\site-packages\adal\authentication_context.py in token_func(self)    302                 self._token_requests_with_user_code[key] = token_request...--> 362                                 wire_response)    363             else:    364                 try:AdalError: Unexpected polling state invalid_client

Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>