Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Azure批处理中持久化输出文件时发生FileUploadMiscError_Python_Python 3.x_Azure_Azure Storage_Azure Batch - Fatal编程技术网

Python 从Azure批处理中持久化输出文件时发生FileUploadMiscError

Python 从Azure批处理中持久化输出文件时发生FileUploadMiscError,python,python-3.x,azure,azure-storage,azure-batch,Python,Python 3.x,Azure,Azure Storage,Azure Batch,我在尝试从Azure批处理执行将日志文件持久化到Azure Blob存储时遇到以下错误-FileUploadMiscError-上载其中一个输出文件时遇到其他错误。这个错误并没有提供很多关于可能出错的信息。我试图检查Microsoft文档中的此错误代码,但它没有提到此特定错误代码。 下面是将任务添加到Azure批处理的相关代码,我已将该任务从C移植到Python以持久化日志文件 注意:我配置的容器是在添加任务时创建的,但是里面没有blob import datetime import loggi

我在尝试从Azure批处理执行将日志文件持久化到Azure Blob存储时遇到以下错误-FileUploadMiscError-上载其中一个输出文件时遇到其他错误。这个错误并没有提供很多关于可能出错的信息。我试图检查Microsoft文档中的此错误代码,但它没有提到此特定错误代码。 下面是将任务添加到Azure批处理的相关代码,我已将该任务从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}")
批处理的OutputFile处理中存在一个错误,如果完整容器URL包含除SAS令牌中包含的查询字符串参数以外的任何查询字符串参数,则会导致批处理无法上载到容器。不幸的是,azure storage blob Python模块在通过make_container_URL生成URL时包含了一个额外的查询字符串参数

这个问题刚刚向我们提出,一个修复程序将在未来几周内发布,但是一个简单的解决方法不是使用make_container_url来创建url,而是自己创建url:container_url='https://{}/{}/{}?{}'。formatblob_服务。primary_端点,blob_细节['container_name',container_sas


生成的URL应如下所示:https://.blob.core.windows.net/?se=2019-01-12T01%3A34%3A05Z&sp=w&sv=2018-03-28&sr=c&sig=-具体来说,它不应该包含restype=container,这是azure存储blob包包含的内容,这是正确的。我找到了答案,并编写了自己的函数,用于在不使用restype参数的情况下生成URL。谢谢