【问题标题】:Problem in running ASGI environments while deploying app Django Rest部署应用程序 Django Rest 时运行 ASGI 环境的问题
【发布时间】:2020-04-19 00:30:13
【问题描述】:

我正在使用 Django 开发一个应用程序,我最初使用 WSGI 环境将它部署在 Google Cloud Platform 上,现在我已经在应用程序中添加并使用了通道,因此我必须从 WSGI 转移到 ASGI,但我得到了使用 ASGI 环境时部署到 Google Cloud Platform 时出错

我收到错误:respiter = self.wsgi(environ, resp.start_response) TypeError: __call__() 接受 2 个位置参数,但给出了 3 个

当我想使用ASGI环境时,我注释了WSGI文件的所有内容,这是我的相关代码:

ASGI 文件:

import os
import django
from channels.routing import get_default_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
django.setup()
application = get_default_application()

WSGI 文件(我已评论):

"""
WSGI config for Frames project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/


import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')

application = get_wsgi_application()"""

ma​​in.py

from Frames.asgi import application
app = application

Settings.py(主要更改,我已从 settings.py 中删除了所有与 WSGI 相关的内容)


ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("localhost", 6379)],
            },
    },
}

如何运行 ASGI 环境?如果我在显示我的代码时遗漏了某些内容,我也可以显示,我无法理解问题所在,我部署 ASGI 应用程序的方式是否正确?

【问题讨论】:

  • 您的应用程序运行情况如何?你的entrypoint 是什么?
  • 它自动从我提到的 main.py 文件加载,它调用 ASGI 文件(这是入口点)
  • 在您评论了 WSGI 的所有内容后,您仍然收到呼吸器错误吗?或者评论完所有 WSGI 后出现的错误是什么?
  • 我得到的唯一呼吸器错误

标签: django google-cloud-platform django-channels django-wsgi asgi


【解决方案1】:

App Engine 标准目前不支持 ASGI。

要使用 ASGI,您应该使用 App Engine Flexible,您可以在其中进一步调整环境。

然后,您可能会发现 GAE flex 文档中有关 Creating Persistent Connections with WebSockets 的指南很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2018-02-18
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 2020-11-02
    相关资源
    最近更新 更多