0

I need to use MSAL for SharePoint authentication and ctx for retrieving data from a folder inside SharePoint using python. Azure AD is already setup . I have used the below code for msal authentication and I am able to retrieve the access token using client id and secret. Now i want to do some sanity checks before extracting my data from share point into S3 Bucket.

Getting below error "errorMessage": "cannot unpack non-iterable NoneType object", "errorType": "TypeError",

def acquire_token():
    """
    Acquire token via MSAL
    """
    authority_url = 'https://login.microsoftonline.com/'
    app = msal.ConfidentialClientApplication(
        client_id=client_id,
        client_credential=client_secret,
        authority=authority
    )
    print("app---->", app)
    result = app.acquire_token_for_client(scopes)
    print("token---->", result)
    return acquire_token


def check_folder_presence(relative_url, ctx):
    try:
        folder = ctx.web.get_folder_by_server_relative_url(relative_url)
        fold_names = []
        folder_info = []
        sub_folders = folder.folders
        ctx.load(sub_folders)
        ctx.execute_query()
        for s_folder in sub_folders:
            fold_names.append(s_folder.properties["Name"])
            folder_info.append(s_folder.properties)
        return fold_names, folder_info

    except Exception as e:
        print('Error in printing the sharepoint library contents: ', e)

def check_file_presence(relative_url, ctx):
    try:
        folder = ctx.web.get_folder_by_server_relative_url(relative_url)
        fold_names = []
        folder_info = []
        sub_folders = folder.files
        ctx.load(sub_folders)
        ctx.execute_query()
        for s_folder in sub_folders:
            fold_names.append(s_folder.properties["Name"])
            folder_info.append(s_folder.properties)
        return fold_names, folder_info

    except Exception as e:
        print('Error in printing the sharepoint library contents: ', e)

The same works fine if i authenticate with ctx . when i change the authentication menthod to msal. getting error.

0 Answers0