importargparsefromoffice365.sharepoint.client_contextimportClientContextfromoffice365.sharepoint.sharing.links.kindimportSharingLinkKindfromtests.settingsimportclient_id,password,site_url,tenant,usernamedefmain():parser=argparse.ArgumentParser(description="Get a file by a sharing link")parser.add_argument("--file-url",default="/sites/team/SitePages/How To Use This Library.aspx",help="server-relative file URL",)args=parser.parse_args()ctx=ClientContext(site_url).with_username_and_password(tenant=tenant,client_id=client_id,username=username,password=password)# Generate sharing link url for a file firstfile=ctx.web.get_file_by_server_relative_url(args.file_url)# Share a fileresult=file.share_link(SharingLinkKind.OrganizationView).execute_query()# Resolve file by sharing link url (guest url)file=ctx.web.get_file_by_guest_url(str(result.value)).execute_query()print(file)if__name__=="__main__":main()