import socket from httplib.exceptions import BadRequest from httplib.httpsocket import HTTPSocket class ServerSocket(HTTPSocket): def read_line(self): try: return super().read_line() except UnicodeDecodeError: raise BadRequest("UnicodeDecodeError")