def get_status_line(status_code): try: phrase = http.HTTPStatus(status_code).phrase.encode() except ValueError: phrase = b'' return b''.join([ b'HTTP/1.1 ', str(status_code).encode(), b' ', phrase, b'\r\n' ])