Google Cloud Function:FunctionsError:OperationError:code = 13,message =由于运行状况检查失败,功能部署失败

时间:2020-09-26 12:20:55

标签: python google-cloud-platform google-cloud-functions

使用以下bash命令进行部署时:

gcloud functions deploy my_gcf --runtime python37 --trigger-http --memory=512MB --region europe-west1 --service-account=my-service-account@my-project.iam.gserviceaccount.com --allow-unauthenticated --verbosity debug

我不断得到:

FunctionsError: OperationError: code=13, message=Function deployment failed due to a health check failure. This usually indicates that your code was built successfully but failed during a test execution. Examine the logs to determine the cause.

不幸的是,在检查日志时,我没有得到以下任何特别的东西:

Error: function terminated. Recommended action: inspect logs for termination reason. Function cannot be initialized.

如您所见,我指定了--verbosity标志,但似乎没有帮助。所有软件包都已安装,并且我遵循文档here来构造存储库:在我的代码中,我同时拥有了requirements.txt文件和已编码的自定义软件包,但是我想我会得到另一种以上错误之一。

我的要求。txt:

beautifulsoup4==4.8.0
boto==2.49.0
boto3==1.13.25
botocore==1.16.25
cachetools==4.1.0
cloudpickle==0.8.1
flask==1.0.2
flask-restplus==0.12.1
functions-framework==2.0.0
gensim==3.8.3
google-api-core==1.17.0
google-api-python-client==1.7.8
google-auth==1.15.0
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.1
google-cloud==0.34.0
google-cloud-core==0.29.1
google-cloud-pubsub==0.45.0
google-cloud-storage==1.14.0
google-cloud-vision==1.0.0
grpc-google-iam-v1==0.12.3
grpcio==1.29.0
gunicorn==19.9.0
jinja2==2.10
jsonschema==3.2.0
more-itertools==8.3.0
nltk==3.4.4
numpy==1.18.4
pandas==1.0.3
protobuf==3.12.1
requests==2.23.0
requests-oauthlib==1.3.0
scikit-learn==0.23.1
scikit-plot==0.3.7
scipy==1.4.1
setuptools==46.4.0
temp
urllib3==1.25.9
werkzeug==0.14.1
yarl==1.4.2

我的main.py:

from flask import abort, escape, jsonify
from werkzeug.exceptions import BadRequest
from src.split.pagetypemodel import MetaModel, PageTypeModel
from src.split.utils import predict_pipeline_split, check_google_json, extract_data_from_json, \
    map_predictions_to_expected_output
import time
import logging
import datetime
import google.cloud.storage as gcs
import tempfile
from os import path
import sys
sys.path.insert(0, path.join(path.dirname(path.realpath(__file__)), 'lib'))
import logging
from google.oauth2 import service_account
import os

MODEL_VERSION = 'v0'
model_split = PageTypeModel()
bucket = gcs.Client().get_bucket('my-bucket')

model_split.load(source = tempfile.gettempdir(), filename = "pagetypemodel_prod",
                 bucket = bucket, storage = "GTEL_SX/split")

def my_gcf(request):

    # set logger
    today = time.gmtime()
    logger = logging.getLogger(__name__)
    logger.info('>>> Received post request at time: {}'.format(today))

    logger.info('1. Checking input json')

    # check if there is any data
    if request.get_json() is None:
        logger.info('Data is not a valid json')
        raise BadRequest('The body of the request does not contain a valid json, please contact AA team')

    if isinstance(request.get_json(), list):
        logger.info('Input json is a list! Correct!!')
        input_body = {
            'responses': request.json
        }
    else:
        # bad format input json
        logger.warning('Json type is not list!!')
        raise BadRequest('Json type is not list')

    logger.info('N pages: {}'.format(len(input_body['responses'])))

    # check if there is data inside input
    if len(input_body['responses']) == 0:
        logger.warning('Received empty list')
        raise BadRequest('Received empty list')

    # check format page
    for i in range(len(input_body['responses'])):
        logger.info('Checking page number {}'.format(i))
        check_google_json(input_body['responses'][i], logger)

    logger.info('2. Extract info from json')
    list_txt, list_labels_ocr = extract_data_from_json(input_body['responses'], logger)

    logger.info('3. Predict')
    predictions = predict_pipeline_split(list_txt, list_labels_ocr, model_split)
    predictions = map_predictions_to_expected_output(predictions)  # format predictions to expected output

    logger.info('4. Return output')
    response = {
        "splitPages": predictions,
        "datetimePrediction": datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
        "version": MODEL_VERSION
    }

    return jsonify(response), 200

提前谢谢

1 个答案:

答案 0 :(得分:1)

即使当前日志在删除时也没有提供任何其他信息:

werkzeug==0.14.1

并替换为:

werkzeug

我能够部署Google Cloud Function。