我在Google Vision API中使用文档文本检测来获取文本 从图像中获取,我有时会在运行程序并锁定笔记本电脑时收到“ google.api_core.exceptions.ServiceUnavailable:503名称解析失败”错误。看起来是网络问题,因为我无法使用同一张图片进行复制。我不明白为什么只有在笔记本电脑锁定时才会发生这种情况。
client = vision.ImageAnnotatorClient()
buffer = io.BytesIO()
image.save(buffer, "PNG")
content = buffer.getvalue()
vision_type_image = vision.types.Image(content=content)
response = client.document_text_detection(image=vision_type_image)
document = response.full_text_annotation
response = self.annotate_image(request, retry=retry, timeout=timeout)
File "/home/sara/pip-envs/env/lib/python3.6/site-packages/google/cloud/vision_helpers/__init__.py", line 72, in annotate_image
r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
File "/home/sara/pip-envs/env/lib/python3.6/site-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 234, in batch_annotate_images
request, retry=retry, timeout=timeout, metadata=metadata
File "/home/sara/pip-envs/env/lib/python3.6/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/home/sara/pip-envs/env/lib/python3.6/site-packages/google/api_core/grpc_helpers.py", line 59, 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```