• 在配置了channels+django的websocket后出现上传文件限制大小的413错误如何解决,及设置默认的错误页面会出现的报错


    找到channels在python包目录如ubutnu18就在/home/xiangkejin/.local/lib/python3.6/site-packages/channels

    找到这个目录下的http.py,编辑

        @sync_to_async
        def handle(self, body):
            """
            Synchronous message processing.
            """
            # Set script prefix from message root_path, turning None into empty string
            script_prefix = self.scope.get("root_path", "") or ""
            if settings.FORCE_SCRIPT_NAME:
                script_prefix = settings.FORCE_SCRIPT_NAME
            set_script_prefix(script_prefix)
            signals.request_started.send(sender=self.__class__, scope=self.scope)
            # Run request through view system
            try:
                request = self.request_class(self.scope, body)
            except UnicodeDecodeError:
                logger.warning(
                    "Bad Request (UnicodeDecodeError)",
                    exc_info=sys.exc_info(),
                    extra={"status_code": 400},
                )
                response = http.HttpResponseBadRequest()
            except RequestTimeout:
                # Parsing the rquest failed, so the response is a Request Timeout error
                response = HttpResponse("408 Request Timeout (upload too slow)", status=408)
            except RequestAborted:
                # Client closed connection on us mid request. Abort!
                return
            #except RequestDataTooBig:   #在你不清楚你要上传的文件最大有多大的时候最好是吧这一段注释掉
            #    response = HttpResponse("413 Payload too large", status=413)   #注释掉
    

      

    然后找到managent/commands/下的runserver.py文件  编辑文件:

    def inner_run(self, *args, **options):
            # Maybe they want the wsgi one?
            if not options.get("use_asgi", True):
                if hasattr(RunserverCommand, "server_cls"):
                    self.server_cls = RunserverCommand.server_cls
                return RunserverCommand.inner_run(self, *args, **options)
            # Run checks
            self.stdout.write("Performing system checks...
    
    ")
            #self.check(display_num_errors=True)  #注释掉这一句
            self.check_migrations()
            # Print helpful text
            quit_command = "CTRL-BREAK" if sys.platform == "win32" else "CONTROL-C"
            now = datetime.datetime.now().strftime("%B %d, %Y - %X")
            self.stdout.write(now)      
  • 相关阅读:
    Kendo UI for jQuery电子表格控件可轻松实现Excel导出
    缩短
    google 插件 消息通知
    C#初学者的Hello World代码_艾孜尔江撰
    HTML简易的用户名密码登录页面_艾孜尔江撰
    一次性打开多个网页的工具脚本_艾孜尔江撰
    使用a标签无法跳转到指定网页的解决办法
    Flutter安装+Vscode+夜神模拟器+android SDK
    gitbook 说明
    两个模块之间项目依赖问题
  • 原文地址:https://www.cnblogs.com/arrow-kejin/p/10730772.html
Copyright © 2020-2023  润新知