So have this module, that imports some files daily in a system. It accepts files with
xls and certain format. It was importing normally every day. But for some reason now I got this
IOError saying there is no such file, but going into directory I see that file.
And two strange things are happening/happened. First I checked this issue on my local server. I copied same files and tried same importation. And it worked (code is identical in both servers).
And then even stranger thing happened, I restarted server numerous times (still gave error) trying to debug the problem. But When I was writing logger to see if correct current directory is used (of course this is not related, but it happened at that time) when importation and archiving of those files happens, somehow it imported without that error, even though I didn’t do anything. I don’t get it how is that possible.
My local server uses Ubuntu
14.04 with python
2.7.6 and remote (where this strange thing happened) – Ubuntu
12.04 with python
And part of the code where error happened:
def archive_file(self, f, arch_dir, add_dt=False, remote=False): """ Gzip and move to archive """ fname = f + '.gz' fname = fname.encode('utf-8') if add_dt: gec_obj = self.pool.get('card.gec.data') dt_str = gec_obj.set_tz(datetime.now()).strftime("%Y-%m-%dT%H:%M:%S") fname = "%s_%s" % (dt_str, fname) gz = gzip.GzipFile(fname, "w") inp_file = open(f) shutil.copyfileobj(inp_file, gz) inp_file.close() if not remote: try: shutil.move(fname.decode('utf-8'), arch_dir) except IOError: raise orm.except_orm(_('Error!'), _('Archive directory %s not found') % (arch_dir)) os.remove(f) gz.close()
Exact place where error was thrown is at
inp_file = open(f).
f variable has only file name (not full path), but current directory is correct. That file is located in
/home/import/daily. And checking on that method what current working directory was, printed me
/home/import/daily/, so it should mean it was looking for a file in a correct place, but somehow thrown error there is no such file.
And one more thing, that file name is used in unicode string for example
f = u'some_file_name.xls
And those files give these warnings:
WARNING *** file size (17378) not 512 + multiple of sector size (512) WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero
But as I said, it still imported on my local ubuntu and later on remote, but I don’t get it how it resolved itself.
Maybe someone can help me solve this puzzle?:)