Я пытаюсь перебрать изображения в каталоге и получить их метки через goodle_api_vision.Это мой код: def run_quickstart (): импорт io import os import cv2 import numpy as np из google.cloudэта часть кода image = types.Image(content=content)
.Полная ошибка:
<class 'bytes'>
<class 'google.cloud.vision_v1.types.Image'>
ERROR:root:AuthMetadataPluginCallback "
<google.auth.transport.grpc.AuthMetadataPlugin object at
0x0000028520DCA2E8>" raised exception!
Traceback (most recent call last):
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-
packages\grpc\_plugin_wrapping.py", line 77, in __call__
callback_state, callback))
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-
packages\google\auth\transport\grpc.py", line 77, in __call__
callback(self._get_authorization_headers(context), None)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site
packages\google\auth\transport\grpc.py", line 61, in
_get_authorization_headers
self._credentials.before_request(
AttributeError: 'str' object has no attribute 'before_request'
Traceback (most recent call last):
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-
packages\google\api_core\grpc_helpers.py", line 54, in error_remapped_callable
return callable_(*args, **kwargs)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 487, in __call__
return _end_unary_response_blocking(state, call, False, deadline)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 437, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Getting metadata from plugin failed with error: 'str' object has no attribute 'before_request')>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "Tutorial.py", line 32, in <module>
run_quickstart()
File "Tutorial.py", line 24, in run_quickstart
response = client.label_detection(image=image)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\vision_helpers\decorators.py", line 117, in inner
response = self.annotate_image(request, retry=retry, timeout=timeout)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\vision_helpers\__init__.py", line 67, in annotate_image
r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\google\cloud\vision_v1\gapic\image_annotator_client.py", line 165, in batch_annotate_images
request, retry=retry, timeout=timeout, metadata=metadata)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\google\api_core\gapic_v1\method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\hi_pe\AppData\Local\Programs\Python\Python36\lib\site-packages\google\api_core\grpc_helpers.py", line 56, 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 Getting metadata from plugin failed with error: 'str' object has no attribute 'before_request'
Я поставил строку content = content.tobytes()
, потому что в противном случае я получаю эту ошибку has type <class 'numpy.ndarray'>, but expected one of: ((<class 'bytes'>,),)
(всегда при этом вызове метода image = types.Image(content=content)
)