在配置了channels+django的websocket後出現上傳文件限制大小的413錯誤如何解決,及設置默認的錯誤頁面會出現的報錯

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

找到這個目錄下的http.py,編輯async

    @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文件  編輯文件:ui

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...\n\n")
        #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)      
相關文章
相關標籤/搜索