making sure that the file_obj has "mode" before trying to access it,
which is needed for working with StringIO file-like objects