Иногда я получаю ошибку
google.api_core.exceptions.ServiceUnavailable: 503 Getting metadata from plugin failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
При запуске
# server/classifiers/gcloud/identifier.py
import io
import os
import json
from google.cloud import vision
from google.cloud.vision import types
from collections import Counter
client = vision.ImageAnnotatorClient()
with io.open("config/labels.json", "r") as f:
LABELS = json.loads(f.read())
def identify_from_string(blob):
image = types.Image(content=blob)
response = client.object_localization(image=image)
labels = response.localized_object_annotations
objects = set(label.name for label in labels)
c = Counter()
for label, s in LABELS.items():
for ob in objects:
if ob in s:
c[label] += s[ob]
if not c: print("Sorry, the server is currently full.")
return str(c)
С ошибкой, выданной в строке с response = client.object_localization(image=image)
. На моем app.py
у меня есть
# server/app.py
import os
import json
from server.classifiers.gcloud import identifier
from flask import Flask, Response, render_template, send_file, request
@app.route('/classify', methods=['POST'])
def classify():
app.logger.info("Got image to /classify")
file = request.files['image']
blob = file.read()
results = identifier.identify_from_string(blob)
return Response(response=json.dumps(dict(response)), status=200)
, где server.classifiers.gcloud.identifier указывает на файл выше. Иногда проблема внезапно исчезает. Есть ли способ обойти это?