Как исправить «google.api_core.exceptions.ServiceUnavailable: 503 Ошибка подключения» при подключении к облачному API Google - PullRequest
1 голос
/ 26 сентября 2019

Я хочу использовать GOOGLE vision API и получаю сообщение об ошибке «google.api_core.exceptions.ServiceUnavailable: 503 Connect Failed».

Я получаю 503 ошибку при подключении к Google vision API, и у меня естьследовал инструкциям шаг за шагом.Ссылка следующая: https://cloud.google.com/vision/docs/quickstart-client-libraries

Я загружаю свой ключевой файл (формат json) и проверяю, включен ли API. Я устанавливаю переменную среды и следую другим инструкциям, поставив os.environ ['GOOGLE_APPLICATION_CREDENTIALS']= r "/ Users / a529157492 / Desktop / application_default_credentials 2.json" прямо в коде.

Однако я все еще получаю код ошибки.

import io
import os


from google.cloud import vision
from google.cloud.vision import types
from google.oauth2 import service_account



os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 
r"/Users/a529157492/Desktop/application_default_credentials 2.json"
client = vision.ImageAnnotatorClient()


file_name = os.path.abspath(r'/Users/a529157492/Desktop/demo-img.jpg')


with io.open(file_name, 'rb') as image_file:
   content = image_file.read()

image = types.Image(content=content)


response = client.label_detection(image=image)
labels = response.label_annotations

print('Labels:')[enter image description here][1]
for label in labels:
    print(label.description)

Однако я получаю следующие ошибки:

Traceback (most recent call last):
File "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/google/api_core/grpc_helpers.py", line 57, in 
error_remapped_callable
   return callable_(*args, **kwargs)
File "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/grpc/_channel.py", line 532, in __call__
   return _end_unary_response_blocking(state, call, False, None)
File "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/grpc/_channel.py", line 466, in _end_unary_response_blocking
   raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
   status = StatusCode.UNAVAILABLE
   details = "Connect Failed"
   debug_error_string = " 
{"created":"@1569469218.801077000","description":"Failed to create 

subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc",
"file_line":2636,"referenced_errors": 
[{"created":"@1569469218.801045000","description":"Pick 

Cancelled","file":"src/core/ext/filters/client_channel/lb_policy/pick_first
/pick_first.cc","file_line":241,"referenced_errors": 
[{"created":"@1569469218.800545000","description":"Connect 
Failed","file":"src/core/ext/filters/client_channel/subchannel.cc",
"file_line":663,"grpc_status":14,"referenced_errors": 
[{"created":"@1569469218.800511000","description":"Failed to connect to 
remote host: FD 
shutdown","file":"src/core/lib/iomgr/ev_poll_posix.cc",
"file_line":532,"grpc_status":14,"os_error":"Timeout 
occurred","referenced_errors": 
[{"created":"@1569469218.800460000","description":"connect() timed 
out","file":"src/core/lib/iomgr/tcp_client_posix.cc","file_line":114}],
"target_address":"ipv4:172.217.27.138:443"}]}]}]}"


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/a529157492/PycharmProjects/untitled7/pictureanalysis.py", line 
24, in <module>
   response = client.label_detection(image=image)
File "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/google/cloud/vision_helpers/decorators.py", line 101, in inner
   response = self.annotate_image(request, retry=retry, timeout=timeout)
File "/Users/a529157492/PycharmProjects/untitled7/venv/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 "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 274, 
in batch_annotate_images
    request, retry=retry, timeout=timeout, metadata=metadata
File "/Users/a529157492/PycharmProjects/untitled7/venv/lib/python3.6/site- 
packages/google/api_core/gapic_v1/method.py", line 143, in __call__
   return wrapped_func(*args, **kwargs)
File "/Users/a529157492/PycharmProjects/untitled7/venv/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 Connect Failed
...