从 Azure Batch 保留输出文件时出现 FileUploadMiscError
FileUploadMiscError while persisting output file from Azure Batch
我在尝试将日志文件从 Azure Batch 执行保存到 Azure Blob 存储时遇到以下错误 - "FileUploadMiscError - A miscellaneous error was encountered while uploading one of the output files"。这个错误并没有提供很多关于可能出了什么问题的信息。我尝试查看 Microsoft 文档以了解此错误代码,但并未提及此特定错误代码。
下面是将任务添加到 Azure Batch 的相关代码,我已将其从 C# 移植到 Python 以保留日志文件。
注意:我配置的容器是在添加任务时创建的,但是里面没有blob。
import datetime
import logging
import os
import azure.storage.blob.models as blob_model
import yaml
from azure.batch import models
from azure.storage.blob.baseblobservice import BaseBlobService
from azure.storage.common.cloudstorageaccount import CloudStorageAccount
from dotenv import load_dotenv
LOG = logging.getLogger(__name__)
def add_tasks(batch_client, job_id, task_id, io_details, blob_details):
task_commands = "This is a placeholder. Actual code has an actual task. This gets completed successfully."
LOG.info("Configuring the blob storage details")
base_blob_service = BaseBlobService(
account_name=blob_details['account_name'],
account_key=blob_details['account_key'])
LOG.info("Base blob service created")
base_blob_service.create_container(
container_name=blob_details['container_name'], fail_on_exist=False)
LOG.info("Container present")
container_sas = base_blob_service.generate_container_shared_access_signature(
container_name=blob_details['container_name'],
permission=blob_model.ContainerPermissions(write=True),
expiry=datetime.datetime.now() + datetime.timedelta(days=1))
LOG.info(f"Container SAS created: {container_sas}")
container_url = base_blob_service.make_container_url(
container_name=blob_details['container_name'], sas_token=container_sas)
LOG.info(f"Container URL created: {container_url}")
# fpath = task_id + '/output.txt'
fpath = task_id
LOG.info(f"Creating output file object:")
out_files_list = list()
out_files = models.OutputFile(
file_pattern=r"../stderr.txt",
destination=models.OutputFileDestination(
container=models.OutputFileBlobContainerDestination(
container_url=container_url, path=fpath)),
upload_options=models.OutputFileUploadOptions(
upload_condition=models.OutputFileUploadCondition.task_completion))
out_files_list.append(out_files)
LOG.info(f"Output files: {out_files_list}")
LOG.info(f"Creating the task now: {task_id}")
task = models.TaskAddParameter(
id=task_id, command_line=task_commands, output_files=out_files_list)
batch_client.task.add(job_id=job_id, task=task)
LOG.info(f"Added task: {task_id}")
Batch 的 OutputFile
处理中存在一个错误,如果完整的容器 URL 包含除 SAS 令牌中包含的参数之外的任何查询字符串参数,它会导致无法上传到容器.不幸的是,azure-storage-blob
Python 模块在通过 make_container_url
.
生成 URL 时包含一个额外的查询字符串参数
我们刚刚收到这个问题,将在未来几周内发布修复程序,但一个简单的解决方法是不要使用 make_container_url
制作 URL,而是自己制作所以:container_url = 'https://{}/{}?{}'.format(blob_service.primary_endpoint, blob_details['container_name'], container_sas)
.
结果 URL 应该看起来像这样: https://<account>.blob.core.windows.net/<container>?se=2019-01-12T01%3A34%3A05Z&sp=w&sv=2018-03-28&sr=c&sig=<sig>
- 具体来说它不应该有 restype=container
(这是 azure-storage-blob
包中包含的内容)
我在尝试将日志文件从 Azure Batch 执行保存到 Azure Blob 存储时遇到以下错误 - "FileUploadMiscError - A miscellaneous error was encountered while uploading one of the output files"。这个错误并没有提供很多关于可能出了什么问题的信息。我尝试查看 Microsoft 文档以了解此错误代码,但并未提及此特定错误代码。 下面是将任务添加到 Azure Batch 的相关代码,我已将其从 C# 移植到 Python 以保留日志文件。
注意:我配置的容器是在添加任务时创建的,但是里面没有blob。
import datetime
import logging
import os
import azure.storage.blob.models as blob_model
import yaml
from azure.batch import models
from azure.storage.blob.baseblobservice import BaseBlobService
from azure.storage.common.cloudstorageaccount import CloudStorageAccount
from dotenv import load_dotenv
LOG = logging.getLogger(__name__)
def add_tasks(batch_client, job_id, task_id, io_details, blob_details):
task_commands = "This is a placeholder. Actual code has an actual task. This gets completed successfully."
LOG.info("Configuring the blob storage details")
base_blob_service = BaseBlobService(
account_name=blob_details['account_name'],
account_key=blob_details['account_key'])
LOG.info("Base blob service created")
base_blob_service.create_container(
container_name=blob_details['container_name'], fail_on_exist=False)
LOG.info("Container present")
container_sas = base_blob_service.generate_container_shared_access_signature(
container_name=blob_details['container_name'],
permission=blob_model.ContainerPermissions(write=True),
expiry=datetime.datetime.now() + datetime.timedelta(days=1))
LOG.info(f"Container SAS created: {container_sas}")
container_url = base_blob_service.make_container_url(
container_name=blob_details['container_name'], sas_token=container_sas)
LOG.info(f"Container URL created: {container_url}")
# fpath = task_id + '/output.txt'
fpath = task_id
LOG.info(f"Creating output file object:")
out_files_list = list()
out_files = models.OutputFile(
file_pattern=r"../stderr.txt",
destination=models.OutputFileDestination(
container=models.OutputFileBlobContainerDestination(
container_url=container_url, path=fpath)),
upload_options=models.OutputFileUploadOptions(
upload_condition=models.OutputFileUploadCondition.task_completion))
out_files_list.append(out_files)
LOG.info(f"Output files: {out_files_list}")
LOG.info(f"Creating the task now: {task_id}")
task = models.TaskAddParameter(
id=task_id, command_line=task_commands, output_files=out_files_list)
batch_client.task.add(job_id=job_id, task=task)
LOG.info(f"Added task: {task_id}")
Batch 的 OutputFile
处理中存在一个错误,如果完整的容器 URL 包含除 SAS 令牌中包含的参数之外的任何查询字符串参数,它会导致无法上传到容器.不幸的是,azure-storage-blob
Python 模块在通过 make_container_url
.
我们刚刚收到这个问题,将在未来几周内发布修复程序,但一个简单的解决方法是不要使用 make_container_url
制作 URL,而是自己制作所以:container_url = 'https://{}/{}?{}'.format(blob_service.primary_endpoint, blob_details['container_name'], container_sas)
.
结果 URL 应该看起来像这样: https://<account>.blob.core.windows.net/<container>?se=2019-01-12T01%3A34%3A05Z&sp=w&sv=2018-03-28&sr=c&sig=<sig>
- 具体来说它不应该有 restype=container
(这是 azure-storage-blob
包中包含的内容)