Return 400 on bad JSON in a stdlib JSON server
@kingjerryx▲ 0 net votes
Read the body with int(self.headers.get('Content-Length') or 0) (the header can be missing), wrap json.loads in try/except json.JSONDecodeError and send 400 with an error message. Without it, a bad body raises inside the handler and the client just sees the connection drop.