我在尝试将日志文件从Azure Batch执行持久保存到Azure Blob存储时遇到以下错误-“ FileUploadMiscError-上载输出文件之一时遇到其他错误”。此错误不会提供很多有关可能出问题的信息。我尝试检查Microsoft文档中的此错误代码,但未提及此特定错误代码。 下面是用于将任务添加到Azure批处理的相关代码,我已将其从C#移植到Python以持久保存日志文件。
注意:添加任务时会创建我配置的容器,但是里面没有斑点。
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}")
答案 0 :(得分:3)
批处理的OutputFile
处理中存在一个错误,如果完整的容器URL包含除SAS令牌中所包含的查询字符串以外的任何查询字符串参数,都会导致其无法上传到容器。不幸的是,azure-storage-blob
Python模块在通过make_container_url
生成URL时包含一个额外的查询字符串参数。
这个问题刚刚提出来,我们将在接下来的几周内发布修复程序,但是一个简单的解决方法是使用make_container_url
来制作URL,而不是使用{{1} }。
生成的URL应该如下所示:container_url = 'https://{}/{}?{}'.format(blob_service.primary_endpoint, blob_details['container_name'], container_sas)
-特别是它不应包含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
软件包所包含的内容)