TypeError: get() ожидал сообщение dict или protobuf, получил [закрыто]Python

Программы на Python
Anonymous
TypeError: get() ожидал сообщение dict или protobuf, получил [закрыто]

Сообщение Anonymous »

Я пытаюсь использовать Google Cloud Vision API для своего проекта, и вот код, в котором возникает ошибка:

Код: Выделить всё

def detect_labels(path):

client = vision.ImageAnnotatorClient()

#with urllib.request.urlopen(path) as image_file:
#    content = image_file.read()

#image = vision.Image(content=content)
req = Request(
url=path,
headers={'User-Agent': 'Mozilla/5.0'}
)
image = urlopen(req).read()

response = client.label_detection(image=image)
labels = response.label_annotations
print("Labels:")

for label in labels:
print(label.description)

if response.error.message:
raise Exception(
"{}\nFor more info on error messages, check: "
"https://cloud.google.com/apis/design/errors".format(response.error.message)
)
Это простой код, который я взял из Интернета и слегка изменил, но при его запуске получаю следующую ошибку:
TypeError: get() ожидал dict или сообщение protobuf, получено
Как устранить эту ошибку? Я использую Python 3.11

Подробнее здесь: https://stackoverflow.com/questions/783 ... lass-bytes

Вернуться в «Python»