Check isinstance(filename, bytes) in case the caller passed a bytes instead of a str