我试图使用他们的python api在windows azure中存储文件但是出现以下错误: -
错误: -
azure.common.AzureMissingResourceHttpError: The specified parent path does not exist.
<?xml version="1.0" encoding="utf-8"?><Error><Code>ParentNotFound</Code><Message>The specified parent path does not exist.
RequestId:ef08c863-001a-0174-6240-e12dfd000000
Time:2017-06-09T16:47:49.6213824Z</Message></Error>
这是python代码: -
file_service = FileService(account_name='example', account_key='fE0mXXgCHRqxrOdxKu9e4BI4o57E6LTUacX40n/KZNw==')
local_file_path = os.path.join(subdir, file)
for subdir, dirs, files in os.walk(rootdir):
for file in files:
result = file_service.create_file_from_path(
'test',
subdir.split(os.path.sep)[-1],
'testfile',
local_file_path,
# content_settings=ContentSettings(content_type='image/png')
)
答案 0 :(得分:0)
根据您的错误信息和代码,我认为您的问题与其他SO线程How to copy file from one directory to other in azure through java service?一样。这是因为在Azure文件存储共享的不存在路径中创建文件,甚至父目录或路径不存在。
因此,您需要先在test
共享中逐个检查并创建这些父目录,然后使用Python中带参数fail_on_exist=True
的方法create_directory(share_name, directory_name, metadata=None, fail_on_exist=False, timeout=None)
进行检查,如下所示
file_service = FileService(account_name='example', account_key='fE0mXXgCHRqxrOdxKu9e4BI4o57E6LTUacX40n/KZNw==')
local_file_path = os.path.join(subdir, file)
for subdir, dirs, files in os.walk(rootdir):
# First to check and create the parent directory whether be exist.
file_service.create_directory('test', subdir, fail_on_exist=True)
for file in files:
result = file_service.create_file_from_path(
'test',
subdir.split(os.path.sep)[-1],
'testfile',
local_file_path,
# content_settings=ContentSettings(content_type='image/png')
)