在我们的一个环境中,我们有以下的Python代码already working like a champ:
def download_files_to_dbfs (site_url, file_url, dbfs_path):
try:
# Credentials for accessing SharePoint
credentials = ClientCredential("Client-ID?",
"Client-Secret?")
ctx = ClientContext(site_url).with_credentials(credentials)
# File_url is the sharepoint url from which you need the list of files
list_source = ctx.web.get_folder_by_server_relative_url(file_url)
files = list_source.files
ctx.load(files)
ctx.execute_query()
for myfiles in files:
rel_url = myfiles.properties["ServerRelativeUrl"]
download_path = dbfs_path + myfiles.properties["Name"]
with open(download_path, "wb") as local_file:
file = ctx.web.get_file_by_server_relative_path(rel_url).download(local_file).execute_query()
print("Downloaded file " + myfiles.properties["Name"])
except Exception as e:
print(e)
我们被授予了自己的工作空间,我们实际上是那里的管理员.
问题是,即使我们的SharePoint admin已经建立了到SharePoint的客户端秘密连接,我们仍然无法通过切换到新的Client-Secret
和Client-ID
来使用相同的功能访问SharePoint.
在上面的代码中,我将"Client-ID?"
和"Client-Secret?"
放在引号中,因为我不确定正确的顺序,也不确定这两个元素是否是在SharePoint和Databricks之间建立连接所需的元素.
我们遇到的错误是Acquire app-only access token failed
,没有提供更多详细信息,只有错误消息本身.我们已经挣扎了好几个星期了:(...