google.api_core.exceptions.ServiceUnavailable: 503 名称解析失败
google.api_core.exceptions.ServiceUnavailable: 503 Name resolution failure
我正在尝试遍历目录中的图像并通过 goodle_api_vision 获取它们的标签。我在 google.api_core.exceptions.ServiceUnavailable 中收到错误:503 名称解析失败 不确定这里的问题是什么?
这是我的代码:
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.join(
os.path.dirname(__file__),
'IronMan.PNG')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
我得到的错误是在这部分代码:
File "geo.py", line 23, in <module>
response = client.label_detection(image=image)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_helpers\decorators.py", line 111, in inner
response = self.annotate_image(request, retry=retry, timeout=timeout)
File "C:\Users\shubhami\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_helpers\__init__.py", line 71, in annotate_image
r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_v1\gapic\image_annotator_client.py", line 233, in batch_annotate_images
request, retry=retry, timeout=timeout, metadata=metadata)
File "C:\Users\shubhami\AppData\Local\Continuum\anaconda3\lib\site-packages\google\api_core\gapic_v1\method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\api_core\grpc_helpers.py", line 61, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 Name resolution failure
尝试从 pyfcm
包 FCMNotification
时遇到同样的问题。如果添加:os.environ['GRPC_DNS_RESOLVER'] = 'native'
我正在尝试遍历目录中的图像并通过 goodle_api_vision 获取它们的标签。我在 google.api_core.exceptions.ServiceUnavailable 中收到错误:503 名称解析失败 不确定这里的问题是什么? 这是我的代码:
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.join(
os.path.dirname(__file__),
'IronMan.PNG')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
我得到的错误是在这部分代码:
File "geo.py", line 23, in <module>
response = client.label_detection(image=image)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_helpers\decorators.py", line 111, in inner
response = self.annotate_image(request, retry=retry, timeout=timeout)
File "C:\Users\shubhami\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_helpers\__init__.py", line 71, in annotate_image
r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\cloud\vision_v1\gapic\image_annotator_client.py", line 233, in batch_annotate_images
request, retry=retry, timeout=timeout, metadata=metadata)
File "C:\Users\shubhami\AppData\Local\Continuum\anaconda3\lib\site-packages\google\api_core\gapic_v1\method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\MyDrive\AppData\Local\Continuum\anaconda3\lib\site-packages\google\api_core\grpc_helpers.py", line 61, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 Name resolution failure
尝试从 pyfcm
包 FCMNotification
时遇到同样的问题。如果添加:os.environ['GRPC_DNS_RESOLVER'] = 'native'