Django Can';无法连接到服务器错误Google应用程序引擎静态文件问题

Django Can';无法连接到服务器错误Google应用程序引擎静态文件问题,django,google-app-engine,google-cloud-platform,web-deployment,google-app-engine-python,Django,Google App Engine,Google Cloud Platform,Web Deployment,Google App Engine Python,我很难使用Django将我的Google App Engine web应用程序从标准切换到flex环境。我需要切换到flex环境,因为我正在我的应用程序中使用模块pdf2image,它使用poppler。以下是我的app.yaml、Dockerfile和my settings.py中的代码片段 注: 在进行这些更改之前,应用程序应在本地运行 可能存在多个错误,如果您能提供有关修复哪些部件的反馈,我们将不胜感激。谢谢 以下是显示的错误: File "/env/lib/python3.7/sit

我很难使用Django将我的Google App Engine web应用程序从
标准
切换到
flex
环境。我需要切换到flex环境,因为我正在我的应用程序中使用模块
pdf2image
,它使用
poppler
。以下是我的app.yaml、Dockerfile和my settings.py中的代码片段

注:

  • 在进行这些更改之前,应用程序应在本地运行
  • 可能存在多个错误,如果您能提供有关修复哪些部件的反馈,我们将不胜感激。谢谢
以下是显示的错误:

File "/env/lib/python3.7/site-packages/MySQLdb/__init__.py", line 84, in Connect return Connection(*args, **kwargs) 
File "/env/lib/python3.7/site-packages/MySQLdb/connections.py", line 164, in __init__ super(Connection, self).__init__(*args, **kwargs2) django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
以下是我们的相关代码片段:

app.yaml:

# [START django_app]
runtime: custom
env: flex
handlers:
# This configures Google App Engine to serve the files in the app's
# static directory.
- url: /static
  static_dir: static/
# This handler routes all requests not caught above to the main app.
# It is required when static routes are defined, but can be omitted
# (along with the entire handlers section) when there are no static
# files defined.
- url: /.*
  script: auto
# [END django_app]
Dockerfile:

FROM gcr.io/google-appengine/python

# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN apt-get update
RUN apt-get install poppler-utils --assume-yes
RUN virtualenv -p python3.7 /env

# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

# Add the application source code.
ADD . /app

# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD gunicorn -b :$PORT main:app
settings.py:

# STATIC_URL = 'https://storage.googleapis.com/tulaibucket/static/'

if os.getenv('GAE_APPLICATION', None):
    # Running on production App Engine, so use a Google Cloud SQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': ‘MYHOST’,
            'USER': ‘MYUSER’,
            'PASSWORD': ‘MYPASSWORD’,
            'NAME': ‘DBNAME’,
        }
    }
else:
    # Running in development, so use a local MySQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '127.0.0.1',
            'PORT': '3306',
            'NAME’: ‘DBNAME’,
            'USER': ‘MYUSER’,
            'PASSWORD': ‘MYPASSWORD’,
        }
    }

如果
settings.py
中的引号有问题,文件应如下所示:

#静态的https://storage.googleapis.com/tulaibucket/static/'
如果os.getenv('GAE_应用程序',无):
#在生产应用程序引擎上运行,所以使用谷歌云SQL数据库。
数据库={
“默认值”:{
'ENGINE':'django.db.backends.mysql',
'主机':'我的主机',
“用户”:“我的用户”,
“密码”:“我的密码”,
'NAME':'DBNAME',
}
}
其他:
#在开发中运行,所以使用本地MySQL数据库。
数据库={
“默认值”:{
'ENGINE':'django.db.backends.mysql',
“主机”:“127.0.0.1”,
“端口”:“3306”,
'NAME':'DBNAME',
“用户”:“我的用户”,
“密码”:“我的密码”,
}
}

GAE\u应用程序
变量未设置为GAE Flexible。使用
GAE\u实例

对于生产,您需要在app.yaml中使用以下内容:

beta_settings:
  cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
beta\u设置:
云计算sql实例: