描述错误: 利用 DataLakeServiceClient,我试图在 Azure Synapse 笔记本中解压缩文件后重命名文件,但在重命名之前我一直成功(代码在 rename_file 方法的最后一行失败)。
我收到以下错误: HttpResponseError: (OutOfRangeInput) 指定的资源名称长度不在允许的范围内。 RequestId:6ef9e79f-a01f-0067-5cb0-62b105000000 时间:2023-03-30T02:34:49.8798540Z 代码:OutOfRangeInput 消息:指定的资源名称长度不在允许的限制内。 RequestId:6ef9e79f-a01f-0067-5cb0-62b105000000 时间:2023-03-30T02:34:49.8798540Z
extraction_path = f"/synfs/{mssparkutils.env.getJobId()}/sink/{self.sink_path}"
with zipfile.ZipFile(compressed_data) as zip_file:
zip_file.extractall(extraction_path)
dl_service_client_source = DataLakeServiceClient(f"https://{lake}.dfs.core.windows.net", credential=credential)
dl_file_system_client_source = dl_service_client_source.get_file_system_client("refined")
dl_directory_client_source = dl_file_system_client_source.get_file_client(self.solution_folder)
files1 = (self.solution_folder + '/' + self.sink_path)
files = dl_file_system_client_source.get_paths(path=files1)
for file in files:
if not file.is_directory:
file_client = dl_file_system_client_source.get_file_client(file.name)
dir_path, file_name1 = os.path.split(file.name)
file_name, file_extension = os.path.splitext(file.name)
new_name = 'test'
new_file_path = os.path.join(dir_path, new_name)
file_client.rename_file(new_file_path)
**我所有的值都正确打印出来,但我仍然收到长度错误。
值的输出:**
文件名: IT/SpatioTemporalAssetCatalog/0_unzipped/1511111156_DodgeDeploy/Manufacturing/ORTHOMOSAIC/TKC/gmwc/TKC_Orthomosaic_export_TueAug31183858312496
files.name: IT/SpatioTemporalAssetCatalog/0_unzipped/1511111156_DodgeDeploy/Manufacturing/ORTHOMOSAIC/TKC/gmwc/TKC_Orthomosaic_export_TueAug31183858312496.kml
new_name: test
new_file_path: IT/SpatioTemporalAssetCatalog/0_unzipped/1511111156_DodgeDeploy/Manufacturing/ORTHOMOSAIC/TKC/gmwc/test
查看 file_name 中的完整路径,容器名称 IT(仅 2 个字符,大写)是这里问题的原因。
容器名称,只能包含小写字母、数字和连字符,并且必须以字母或数字开头。每个连字符的前后必须有一个非连字符。容器名称的长度必须介于 3 到 63 个字符之间。更多信息在这里。希望这会有所帮助。