首页 > 解决方案 > 来自 azure.storage.blob 的 python 方法 get_service_stats 的问题

问题描述

我在使用 get_service_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

标签: python-3.xazureazure-blob-storage

解决方案


我在下面总结了我的建议。

get_service_statsAzure Python 存储 SDK中的方法azure.storage.blob只有在为存储帐户启用了读取访问异地冗余复制时才能调用。换句话说,在调用该方法之前,我们应该在辅助区域中具有读取权限。更多详情,请参阅此处此处


推荐阅读