473,246 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

[tarfile] Difficultis catching an exception

Hello,

I'm trying to catch an "EOFError" exception that occurs when reading
truncated tarfile. Here's my routine, and below that the callback
trace. Note that although I'm trying to catch all TarFile exceptions,
the tarfile.EOFError ecxeption, and the global EOFError exception, the
program still falls through and fails.

def query_archive(batch_base):
arc_name = os.path.join(archive_dir, 'B_'+batch_base+'.tar.bz2')
sys.stderr.write('Archive: %s ' % arc_name)
try:
archive = tarfile.open(arc_name, 'r:bz2')
members = archive.getmembers()
except tarfile.TarError, EOFError, tarfile.EOFError:
sys.stderr.write("corrupt.\n")
db.execute('UPDATE Archives SET Status=2 WHERE BatchBase=?',
(batch_base, ))
update_batchinfo(members, batch_base)
return 0

Archive: f:/wafermap_archive/B_48380.tar.bz2 Traceback (most recent
call last):
File "./wmap", line 11, in <module>
task.run(command, args)
File "/cygdrive/h/wafermaps/wmap_import.py", line 142, in run
query_archive(batch_base)
File "/cygdrive/h/wafermaps/wmap_import.py", line 95, in
query_archive
members = archive.getmembers()
File "/usr/lib/python2.5/tarfile.py", line 1282, in getmembers
self._load() # all members, we first have to
File "/usr/lib/python2.5/tarfile.py", line 2003, in _load
tarinfo = self.next()
File "/usr/lib/python2.5/tarfile.py", line 1809, in next
self.fileobj.seek(self.offset)
EOFError: compressed file ended before the logical end-of-stream was
detected
Aug 20 '08 #1
1 2556
On Wed, 20 Aug 2008 02:07:33 -0700 (PDT), bo*******@googlemail.com wrote:
I'm trying to catch an "EOFError" exception that occurs when reading
truncated tarfile. Here's my routine, and below that the callback
trace. Note that although I'm trying to catch all TarFile exceptions,
the tarfile.EOFError ecxeption, and the global EOFError exception, the
program still falls through and fails.
....
except tarfile.TarError, EOFError, tarfile.EOFError:
....

Multiple exceptions should be parenthesized. BTW, are you sure
your tarfile has EOFError attribute?
Try this:

....
except (tarfile.TarError, EOFError):
....

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Aug 20 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh Smith | last post by:
In Python 2.3 there is a new library for handling tarfiles. However, there doesn't seem to be any documentation on handling end-of-tape conditions. I've googled for it and checked the docs, I've...
8
by: Jay Donnell | last post by:
Is there a way to use the tarfile module to recursively compress the contents of a directory and maintain the directory structure in the tar archive? Simply doing os.system('tar -czvf ' +...
5
by: Matt Doucleff | last post by:
Hi everyone! I must be doing something wrong here :) I have a tarball that contains a single file whose contents are a pickled object. I would like to unpickle the object directly from the...
8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
1
by: Beowulf | last post by:
Hello, I'm using Python to automate admin tasks on my job. We use Windoze 2000 as desktop platform. When executing this daily backup scripts I get the following error: Traceback (most recent...
1
by: Matthew Thorley | last post by:
I've been using tarfile like this import tarfile tar = tarfile.open('path_to_tar_archive', 'r:gz') But I need to use it like this: archive = open('path_to_tar_archive', 'r') tar =...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
6
by: sebastian.noack | last post by:
Hi, is there a way to or at least a reason why I can not use tarfile to create a gzip or bunzip2 compressed archive in the memory? You might might wanna answer "use StringIO" but this isn't...
6
by: Terry Carroll | last post by:
I am trying to do something with a very large tarfile from within Python, and am running into memory constraints. The tarfile in question is a 4-gigabyte datafile from freedb.org,...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.