gpt4 book ai didi

python - 保留 Azure Batch 中的输出文件时出现 FileUploadMiscError

转载 作者:行者123 更新时间:2023-11-28 22:13:13 24 4
gpt4 key购买 nike

我在尝试通过 Azure Batch 执行将日志文件保存到 Azure Blob 存储时遇到以下错误 - “FileUploadMiscError - 上传输出文件之一时遇到其他错误”。此错误并未提供有关可能出现问题的大量信息。我尝试检查 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 token 中包含的参数以外的任何查询字符串参数,则会导致无法上传到容器。不幸的是,azure-storage-blob通过 make_container_url 生成 URL 时,Python 模块包含一个额外的查询字符串参数.

这个问题刚刚向我们提出,修复程序将在未来几周内发布,但一个简单的解决方法是不使用 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 包所包含的内容)

关于python - 保留 Azure Batch 中的输出文件时出现 FileUploadMiscError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54124958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com