代码之家  ›  专栏  ›  技术社区  ›  Rafael

python方法从azure.storage.blob获取\服务\统计信息时出现问题

  •  0
  • Rafael  · 技术社区  · 5 年前

    get\u service\u stats方法有问题:

    azure.core.exceptions.ServiceRequestError:<urllib3.connection.VerifiedHTTPSConnection对象位于0x7f6e32d5d240>:无法建立新连接:[Errno-2]名称或服务未知

    方法:

     def geo(self):
            
            # Create a logger for the 'azure.storage.blob' SDK
            logger = logging.getLogger('azure.storage.blob')
            logger.setLevel(logging.DEBUG)
            # Configure a console output
            handler = logging.StreamHandler(stream=sys.stdout)
            logger.addHandler(handler)
            bloba = BlobServiceClient.from_connection_string(self.access,logging_enable=True)
            acc = bloba.get_service_stats(logging_enable=True)
    

    我可以使用一个对象(以bloba为例)来连接、上传和下载存储。我将存储设置为GRS(地理复制),但需要获取地理复制的状态(活动、无效等)

    登录中:

    # python3 main.py 
    Connected to Storage Account!
    Request URL: 'https://rpaivatesting123-secondary.blob.core.windows.net/?restype=service&comp=stats'
    Request method: 'GET'
    Request headers:
        'Accept': 'application/xml'
        'x-ms-version': '2019-12-12'
        'x-ms-date': 'Wed, 11 Nov 2020 21:09:52 GMT'
        'x-ms-client-request-id': '3d73d876-2462-11eb-a223-7cb27d33114d'
        'User-Agent': 'azsdk-python-storage-blob/12.5.0 Python/3.6.9 (Linux-5.4.0-48-generic-x86_64-with-Ubuntu-18.04-bionic)'
        'Authorization': '*****'
    Request body:
    None
    Request URL: 'https://rpaivatesting123-secondary.blob.core.windows.net/?restype=service&comp=stats'
    Request method: 'GET'
    Request headers:
        'Accept': 'application/xml'
        'x-ms-version': '2019-12-12'
        'x-ms-date': 'Wed, 11 Nov 2020 21:09:52 GMT'
        'x-ms-client-request-id': '3d73d876-2462-11eb-a223-7cb27d33114d'
        'User-Agent': 'azsdk-python-storage-blob/12.5.0 Python/3.6.9 (Linux-5.4.0-48-generic-x86_64-with-Ubuntu-18.04-bionic)'
        'Authorization': '*****'
    Request body:
    None
    

    已降级sdk:

    Request body:
    None
    Tuple timeout setting is deprecated
    Traceback (most recent call last):
      File "main.py", line 16, in <module>
        health_check.geo()
      File "/root/sarah/DR/devops-toolbox/azure-storage-health-check/scripts/azure_storage_operations.py", line 113, in geo
        acc = bloba.get_service_stats(logging_enable=True)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer
        return func(*args, **kwargs)
      File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_blob_service_client.py", line 257, in get_service_stats
        timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs)
      File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_generated/operations/_service_operations.py", line 229, in get_statistics
        pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 211, in run
        return first_node.send(pipeline_request)  # type: ignore
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      [Previous line repeated 5 more times]
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/policies/_redirect.py", line 157, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_shared/policies.py", line 543, in send
        raise err
      File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_shared/policies.py", line 517, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_shared/policies.py", line 318, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/_base.py", line 103, in send
        self._sender.send(request.http_request, **request.context.options),
      File "/usr/local/lib/python3.6/dist-packages/azure/core/pipeline/transport/_requests_basic.py", line 284, in send
        raise error
    azure.core.exceptions.ServiceRequestError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f11404867b8>: Failed to establish a new connection: [Errno -2] Name or service not known
    
    0 回复  |  直到 5 年前
        1
  •  1
  •   Jim Xu    5 年前

    我将我的建议总结如下。

    方法 get_service_stats 在Azure python存储SDK中 azure.storage.blob 仅当为存储帐户启用了读访问地理冗余复制时,才能调用。换句话说,在调用该方法之前,我们应该在辅助区域中拥有读取权限。有关详细信息,请参阅 here here .