IOError – no such file or directory (no reason why) and suddenly resolves itself?

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 2.7.3

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('')
        dt_str = gec_obj.set_tz("%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)
    if not remote:
            shutil.move(fname.decode('utf-8'), arch_dir)
        except IOError:
            raise orm.except_orm(_('Error!'),
                _('Archive directory %s not found') % (arch_dir))                    

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?:)

Source: ubuntu

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.