django - Gcloud 应用部署失败使用 python+django+gunicorn + worker 启动失败

标签 django google-app-engine gunicorn gcloud

我正在尝试使用 django 部署一个网站/webapp...构建了 app.yaml 和 requirements.txt...一切都完成了,当我点击 gcloud app deploy 时,出现以下错误最后登录..

DONE
-----------------------------------------------------------------------------------------------------------------------------------------

Updating service [default] (this may take several minutes)...failed.                                                                    
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error:
[2019-03-18 03:14:29 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2019-03-18 03:14:29 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2019-03-18 03:14:29 +0000] [1] [INFO] Using worker: sync
[2019-03-18 03:14:29 +0000] [9] [INFO] Booting worker with pid: 9
[2019-03-18 03:14:29 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
[2019-03-18 03:14:29 +0000] [9] [INFO] Worker exiting (pid: 9)
[2019-03-18 03:14:29 +0000] [1] [INFO] Shutting down: Master
[2019-03-18 03:14:29 +0000] [1] [INFO] Reason: Worker failed to boot.

这是我的 app.yaml

runtime: python

api_version: 1
threadsafe: true

# the PROJECT-DIRECTORY is the one with settings.py and wsgi.py
entrypoint: gunicorn -b :$PORT ~/NovUs/rec/rec.wsgi
# specific to a GUnicorn HTTP server deployment
env: flex 
# for Google Cloud Flexible App Engine

# any environment variables you want to pass to your application.
# accessible through os.environ['VARIABLE_NAME']
env_variables:
# the secret key used for the Django app (from PROJECT-DIRECTORY/settings.py)
  SECRET_KEY: '***i removed this***' 
  DEBUG: 'False' # always False for deployment

# everything after /cloudsql/ can be found by entering >> gcloud sql instances describe DATABASE-NAME << in your Terminal
# the DATABASE-NAME is the name you gave your project's PostgreSQL database
# the second line from the describe output called connectionName can be copied and pasted after /cloudsql/
  DB_HOST: '/cloudsql/ final-234816:us-central1:novusdb'
  DB_PORT: '5432' # PostgreSQL port
  DB_NAME: 'novusdb'
  DB_USER: 'postgres' # either 'postgres' (default) or one you created on the PostgreSQL instance page
  DB_PASSWORD: ''

  STATIC_URL: 'https://storage.googleapis.com/BUCKET-NAME/static/' # this is the url that you sync static files to

handlers:
- url: /static
  static_dir: static

- url: /
  script: home.app

- url: /index\.html
  script: home.app

- url: /stylesheets
  static_dir: stylesheets

- url: /(.*\.(gif|png|jpg))$
  static_files: static/\1
  upload: static/.*\.(gif|png|jpg)$

- url: /admin/.*
  script: admin.app
  login: admin

- url: /.*
  script: not_found.app

beta_settings:
# from command >> gcloud sql instances describe DATABASE-NAME <<
  cloud_sql_instances: final-234816:us-central1:novusdb 

#runtime_config:
#python_version: 2 # enter your Python version BASE ONLY here. Enter 2 for 2.7.9 or 3 for 3.6.4

#manual_scaling:
#  instances: 1
#resources:
#  cpu: 1
#  memory_gb: 0.5
#  disk_size_gb: 10   

在我的 settings.py 中 WSGI_APPLICATION = 'rec.wsgi.application' 即使我将其更改为 WSGI_APPLICATION = 'wsgi.application' 它没有解决,错误仍然存​​在。

我已经尝试使用 main:app 编辑入口点,问题是一样的.... 有人请解决这个问题。谢谢

最佳答案

通常可能有 2 个问题,前一段时间在 Google App Engine 上部署 Dash 应用程序时遇到了这个问题。

GAE 的 gunicorn 版本可能存在版本冲突。请改用 gunicorn 19.7.1 或更高版本。我在使用旧版本的 gunicorn 时遇到了同样的问题。

另一个冲突可能是 requirements.txt 与 main.py 入口点不在同一目录中。因此,应用程序将在没有安装所有包的情况下进行部署,这在部署到 GAE 时不会返回任何错误。

关于django - Gcloud 应用部署失败使用 python+django+gunicorn + worker 启动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55214396/

相关文章:

java - 获取http get后,我应该以什么格式从django响应到android?

django - 在 Snow Leopard 上安装 PostgreSQL 和 pyscopg2

google-app-engine - 在本地网络中运行 Google App Engine 应用程序(GWT 开发插件)

python - 导入错误 : No module named PBKDF2

google-app-engine - 如何管理谷歌应用引擎服务帐户私钥?

Gunicorn worker 超时错误

django - 使用 gevent socket.py 时无法使用 Django 连接到 smtp 服务器

python - 如何在 django 序列化器 SlugRelatedField 中获取反向关系

python - 当从 Upstart 运行时没有获得环境变量时,Gunicorn + Django 不起作用

Django MongoDB 问题