无法在Google App Engine Flex环境中部署Python Flask应用程序

时间:2018-10-25 17:14:46

标签: python google-app-engine flask google-cloud-platform

我已经在多个地方搜索过,并尝试了多种方法来找到解决方案。但是没有任何帮助,请您帮我提供解决方案。在Google App Engine灵活的环境中托管python flask应用程序变得异常困难。 Python代码:“ getresource.py”

Here是Google部署Python Flask应用程序的链接

这是简单的代码:

from flask import Flask, jsonify
from pymysql import connections, ProgrammingError, DatabaseError, MySQLError, DataError
from os import environ

DB_HOST = environ.get("DB_HOST")
USER = environ.get("USER")
PWD = environ.get("PASSWORD")
DATABASE = environ.get("DATABASE")

app = Flask(__name__)

dbconn = connections.Connection(
                                host=DB_HOST,
                                port=3306,
                                user=USER,
                                password=PWD,
                                db=DATABASE
                                )

@app.route("/getResource/<id>", methods=['GET'])
def getresource(id):
    result = ()
    select_sql = "SELECT `id`, `firstName`, `middleName`, `lastName`, `listOfTechWorkedOn`, `certifications`, `projects`, `applicationWorkLoadTypes` FROM `resource` WHERE `id`=%s"
    cursor = dbconn.cursor()

    try:
        cursor.execute(select_sql, (id))
        result = cursor.fetchone()

        response = {}
        response['id'] = result[0]
        response['firstName'] = result[1]
        response['middleName'] = result[2]
        response['lastName'] = result[3]
        response['listOfTechWorkedOn'] = result[4]
        response['certifications'] = result[5]
        response['projects'] = result[6]
        response['applicationWorkLoadTypes'] = result[7]

        return jsonify(response)

    except ProgrammingError as p:
        return 
    except DatabaseError as d:
        return d
    except MySQLError as m:
        return m
    except DataError as de:
        return de

    dbconn.close()

if __name__ == '__main__':
    app.run(host='127.0.0.1',port=8080, debug=True)

这是app.yaml文件

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT getresource:app
service: getresource

runtime_config:
  python_version: 3

manual_scaling:
  instances: 1

env_variables:
  DB_HOST: "1.2.3.4"
  USER: "root"
  PASSWORD: "abcdefg"
  DATABASE: "abcd"

requirements.txt文件

Flask==1.0.2
gunicorn==19.9.0
PyMySQL==0.9.2

我收到以下错误:“ gcloud应用程序部署”

错误:(gcloud.app.deploy)错误响应:[13]部署期间发生内部错误。

我已经尝试了多种方法,例如更改python代码,将Google谷歌云库放入requirements.txt,更改端口,服务名称等。但是似乎没有任何效果。

令人惊讶的是,我在堆栈驱动程序日志中也没有得到错误跟踪。而且Google似乎没有适当的答案(至少从我做过的所有谷歌搜索中)

gcloud版本

Google Cloud SDK 222.0.0
bq 2.0.36
core 2018.10.19
gsutil 4.34

**

  • 编辑:

**感谢您的答复。我尝试了所有选项,但是在以下调试消息中得到了相同的错误。我不能用它做任何事

感谢您的回复。我尝试了所有建议的选项,但得到相同的错误。以下是调试日志,我无法使用它进行调试。

Updating service [getresource] (this may take several minutes)...failed.
DEBUG: (gcloud.app.deploy) Error Response: [13] An internal error occurred during deployment.
Traceback (most recent call last):
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 841, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\backend.py", line 770, in Run
    resources = command_instance.Run(args)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\surface\app\deploy.py", line 90, in Run
    parallel_build=False)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 620, in RunDeploy
    flex_image_build_option=flex_image_build_option)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 422, in Deploy
    extra_config_settings)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\appengine_api_client.py", line 207, in DeployService
    poller=done_poller)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\operations_util.py", line 315, in WaitForOperation
    sleep_ms=retry_interval)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 254, in WaitFor
    sleep_ms, _StatusUpdate)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 316, in PollUntilDone
    sleep_ms=sleep_ms)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\util\retry.py", line 229, in RetryOnResult
    if not should_retry(result, state):
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\util\waiter.py", line 310, in _IsNotDone
    return not poller.IsDone(operation)
  File "C:\Users\M1044921\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\api_lib\app\operations_util.py", line 184, in IsDone
    encoding.MessageToPyValue(operation.error)))
OperationError: Error Response: [13] An internal error occurred during deployment.
ERROR: (gcloud.app.deploy) Error Response: [13] An internal error occurred during deployment.

0 个答案:

没有答案