473,699 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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.EOFErro r ecxeption, and the global EOFError exception, the
program still falls through and fails.

def query_archive(b atch_base):
arc_name = os.path.join(ar chive_dir, 'B_'+batch_base +'.tar.bz2')
sys.stderr.writ e('Archive: %s ' % arc_name)
try:
archive = tarfile.open(ar c_name, 'r:bz2')
members = archive.getmemb ers()
except tarfile.TarErro r, EOFError, tarfile.EOFErro r:
sys.stderr.writ e("corrupt.\n ")
db.execute('UPD ATE Archives SET Status=2 WHERE BatchBase=?',
(batch_base, ))
update_batchinf o(members, batch_base)
return 0

Archive: f:/wafermap_archiv e/B_48380.tar.bz2 Traceback (most recent
call last):
File "./wmap", line 11, in <module>
task.run(comman d, args)
File "/cygdrive/h/wafermaps/wmap_import.py" , line 142, in run
query_archive(b atch_base)
File "/cygdrive/h/wafermaps/wmap_import.py" , line 95, in
query_archive
members = archive.getmemb ers()
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.se ek(self.offset)
EOFError: compressed file ended before the logical end-of-stream was
detected
Aug 20 '08 #1
1 2581
On Wed, 20 Aug 2008 02:07:33 -0700 (PDT), bo*******@googl email.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.EOFErro r ecxeption, and the global EOFError exception, the
program still falls through and fails.
....
except tarfile.TarErro r, EOFError, tarfile.EOFErro r:
....

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

....
except (tarfile.TarErr or, 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
1759
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 even looked into the modules src and all I found was an end of file exception that might do what I'm looking for, but might not. Anyone have any pointers/help? TIA
8
11137
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 ' + fileName +'.tar.gz ' + directory) works great on linux, but I need this script to work on windows as well :(
5
4858
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 tarball using the file-like object provided by extractfile(). Attempts to do this result in EOFError. However if I first extract to a temporary file, then unpickle from there, it works. The below code reproduces the problem (on my machine at...
8
8840
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 compressed tarfiles... :( Any thoughts on what I can do to get around this?
1
1923
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 call last): File "C:\UTILS\backup.py", line 8, in ? TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2') File "C:\Python23\lib\tarfile.py", line 875, in open
1
3140
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 = tarfile.open(archive.readlines())
7
2337
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 of code, when System.Exception seems to get the job done for me. My application is an ASP.Net intranet site. When I catch an exception, I log the stack trace and deal with it, normally by displaying an error
6
6010
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 such easy as it seems to be. ;) I am using Python 2.5.2, by the way. I think this is a bug in at least in this version of python, but maybe StringIO isn't just file-like enough for this "korky" tarfile module. But this would conflict with its...
6
7472
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, http://ftp.freedb.org/pub/freedb/ , and has about 2.5 million members in it. Here's a simple toy program that just goes through and counts the number of members in the tarfile, printing a status message every N records (N=10,000 for the smaller file;...
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.