I'm trying to connect to company sharepoint and use one of the example codes i found in this topic:
the first lines of the code worked, I got "Authenticated into sharepoint as:********"
after I used this and it worked also
####Function for extracting the file names of a folder in sharepoint###
###If you want to extract the folder names instead of file names, you have to change "sub_folders = folder.files" to "sub_folders = folder.folders" in the below function
global print_folder_contents
def print_folder_contents(ctx, folder_url_shrpt):
try:
folder = ctx.web.get_folder_by_server_relative_url(folder_url_shrpt)
fold_names = []
sub_folders = folder.files #Replace files with folders for getting list of folders
ctx.load(sub_folders)
ctx.execute_query()
for s_folder in sub_folders:
fold_names.append(s_folder.properties["Name"])
return fold_names
except Exception as e:
print('Problem printing out library contents: ', e)
Than I called the function to print the list of the elements with this code
# Call the function by giving your folder URL as input
filelist_shrpt=print_folder_contents(ctx,folder_url_shrpt)
#Print the list of files present in the folder
print(filelist_shrpt)
and I got this output:
"Problem printing out library contents: ('-1, System.UriFormatException', 'Invalid URI: The Authority/Host could not be parsed.', "500 Server Error: Internal Server Error for url: https://mycompany.sharepoint.com/sites/mysharepointpage/_api/Web/getFolderByServerRelativeUrl('https:%2F%2Fmycompany.sharepoint.com%2Fsites%2FKmysharepointpage%2FDocuments%2520partages%2FGeneral%2F')/Files") None"
someone can help me with this issue?