code: def autodecode(self, a_bytes):
          
          try:  # 如果装了chardet
              analysis = chardet.detect(a_bytes)
              if analysis["confidence"] >= 0.75:  # 如果可信
                  return (self.decode(a_bytes, analysis["encoding"])[0],
                          analysis["encoding"])
              else:  # 如果不可信, 打印异常
                  raise Exception("Failed to detect encoding. (%s, %s)" % (
                      analysis["confidence"],
                      analysis["encoding"]))
          except NameError:  # 如果没有装chardet
              print(
                  "Warning! chardet not found. Use utf-8 as default encoding instead.")
              return (a_bytes.decode("utf-8")[0],
                      "utf-8")
docs: Automatically detect encoding, and decode bytes.