Получение сообщения об ошибке: «Политика повторных попыток не допускает повторных попыток» при попытке загрузить содержимое из хранилища BLOB-объектов Azure с использованием приведенного ниже кода Python - PullRequest
0 голосов
/ 04 мая 2018

Я использую следующий код Python, который рекурсивно загружает содержимое: (например, содержимое '/demo/test1' демо-контейнер)

def download_contents_azure(self,
                            session,
                            content,
                            dir_name) :
    """downloads the specified contents from Azure cloud
    Args :
        session       (obj)      --      Azure blob session object
        content       (list)     --      Part of the subclient content which has to be downloaded from the cloud
        dir_name      (str)      --      Name of the folder where the specified contents are to be downloaded

    Returns :
        None
    """
    os.mkdir(dir_name)
    for item in content :
        os.chdir(dir_name)
        path_to_file = ("/".join(item.strip("/").split('/')[1:]))
        container_name = Path(item).parts[1]
        generator = session.list_blobs(container_name)
        obj_list = []
        for j in generator :
            obj_list.append(j.name)
        if path_to_file == "" :
            self.download_container_azure(session,container_name)
            os.chdir(self.automation_directory)
        elif path_to_file in obj_list :
            if os.path.exists(container_name) is False:
                os.mkdir(container_name)
            os.chdir(container_name)
            head, tail = os.path.split("{}".format(path_to_file))
            if (os.path.isdir(os.getcwd()+ "/" + head)):
                try :
                    print(item)
                    session.get_blob_to_path(container_name,path_to_file,os.getcwd()+ "/" + head + "/" + tail)
                except azure.common.AzureMissingResourceHttpError:
                    self.log.error("exception")
            else:
                """create the diretcory and download the file to it"""
                os.makedirs(os.getcwd()+ "/" + head, exist_ok=True)
                try :
                    print(item)
                    session.get_blob_to_path(container_name,path_to_file,os.getcwd()+ "/" + head + "/" + tail)
                except azure.common.AzureMissingResourceHttpError:
                    self.log.error("exception")
        else :
            generator = session.list_blobs(container_name,path_to_file+'/',delimiter='/')
            self.log.info("got blobs in gen")
            if os.path.exists(container_name) is False:
                os.mkdir(container_name)
            os.chdir(container_name)
            """code below lists all the blobs in the container and downloads them one after another"""
            for blob in generator:
                """check if the path contains a folder structure, create the folder structure"""
                if "/" in "{}".format(blob.name):
                    """extract the folder path and check if that folder exists locally, and if not create it"""
                    head, tail = os.path.split("{}".format(blob.name))
                    if len(tail) != 0 :
                        if (os.path.isdir(os.getcwd()+ "/" + head)):
                            """download the files to this directory"""
                            try :
                                print(blob.name)
                                session.get_blob_to_path(container_name,blob.name,os.getcwd()+ "/" + head + "/" + tail)
                            except azure.common.AzureMissingResourceHttpError:
                                self.log.error("exception")
                        else:
                            """create the diretcory and download the file to it"""
                            os.makedirs(os.getcwd()+ "/" + head, exist_ok=True)
                            try :
                                print(blob.name)
                                session.get_blob_to_path(container_name,blob.name,os.getcwd()+ "/" + head + "/" + tail)
                            except azure.common.AzureMissingResourceHttpError:
                                self.log.error("exception")
                    else :
                        self.recur(session,container_name,blob.name)

                else:
                    try :
                        print(blob.name)
                        session.get_blob_to_path(container_name,blob.name,blob.name)
                    except azure.common.AzureMissingResourceHttpError:
                        self.log.error("exception")

        os.chdir(self.automation_directory)

Я могу загрузить все содержимое правильно, но после загрузки я получаю следующую ошибку:

Client-Request-ID = aaaf7986-4f79-11e8-8e26-00155dbf7128 Политика повторных попыток не допускается повторная попытка: Server-Timestamp = Пт, 04 мая 2018 г. 09:01:00 GMT, идентификатор запроса сервера = e3660206-301e-002e-1c86-e36e5f000000, HTTP код состояния = 404, исключение = указанный BLOB-объект не exist.ErrorCode: BlobNotFound BlobNotFound указанный блоб не exist.RequestId: e3660206-301e-002e-1c86-e36e5f000000Time: 2018-05-04T09: 01: 00.8232375Z

.

Если я использую нативный Python и вызываю этот метод, я не вижу никаких исключений. Может ли кто-нибудь помочь мне избежать этого исключения, чтобы я мог продолжить работу с остальным кодом?

1 Ответ

0 голосов
/ 10 мая 2018

Если посмотреть на файл storageclient.py, причиной возникновения этой ошибки является отсутствие повторных попыток: https://github.com/Azure/azure-storage-python/blob/master/azure-storage-common/azure/storage/common/storageclient.py

В репозитории github отображается следующее:

 # Determine whether a retry should be performed and if so, how 
            # long to wait before performing retry.
            retry_interval = self.retry(retry_context)
            if retry_interval is not None:
                # Execute the callback
                if self.retry_callback:
                    self.retry_callback(retry_context)

                logger.info(
                    "%s Retry policy is allowing a retry: Retry count=%s, Interval=%s.",
                    client_request_id_prefix,
                    retry_context.count,
                    retry_interval)

                # Sleep for the desired retry interval
                sleep(retry_interval)
            else:
                logger.error("%s Retry policy did not allow for a retry: "
                             "%s, HTTP status code=%s, Exception=%s.",
                             client_request_id_prefix,
                             timestamp_and_request_id,
                             status_code,
                             exception_str_in_one_line)
                raise ex

Та же самая ошибка, которую вы получаете, указана в logger.error . Я бы предложил добавить повтор, который должен решить проблему.

...