django正常運行卻報錯的處理方法
出處 : https://www.infvie.com/ops-notes/django-normal-operation-error
報錯一:self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] 您的主機中的軟件中止了一個已建立的連接。
解決方法:找到python/Lib/socketserver.py文件,修改SocketWriter類的write方法,具體如下:
def write(self, b): try: self._sock.sendall(b) except Exception as e: self._sock.close() with memoryview(b) as view: return view.nbytes
報錯二:return self.environ[‘SERVER_PROTOCOL’].upper() != 'HTTP/0.9 TypeError: ‘NoneType’ object is not subscriptable
解決方法:打開python\lib\wsgiref\handlers.py文件,修改client_is_modern函數,具體如下:
def client_is_modern(self): """True if client can accept status and headers""" try: cmp = self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9' except Exception as e: cmp = False return cmp
報錯三:self.status.split(’ ',1)[0], self.bytes_sent AttributeError: ‘NoneType’ object has no attribute 'split
解決方法:打開python\lib\wsgiref\simple_server.py文件,修改ServerHandler類,具體如下:
class ServerHandler(SimpleHandler): server_software = software_version def close(self): try: self.request_handler.log_request( self.status.split(' ', 1)[0], self.bytes_sent ) SimpleHandler.close(self) except Exception as e: SimpleHandler.close(self)
報錯四:“GET /favicon.ico HTTP/1.1” 404 3163
解決方法:在static文件下的image文件添加一個favicon.ico圖片,然后在頁面頭部加入
注:具體路徑看自己定義的內容,或有差異.
報錯五:GET /c_hello?asker=backuper HTTP/1.1" 404 3166 Not Found: /c_hello
解決方法:暫時未找到!!!有懂得解決的希望分享一下,或者我后續找到了再更新一下。

