Hello everyone,
I need some tar functionality for my program. Currently the following
code properly displays tar archives, and tar.gz archives. However, it
chokes on tar.bz2 archives with the following error:
File "mail_filter.py", line 262, in extract_archive
tar_archive = tarfile.open('', 'r', fileobj)
File "/usr/lib/python2.3/tarfile.py", line 900, in open
return func(name, "r", fileobj)
File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open
raise ValueError, "no support for external file objects"
ValueError: no support for external file objects
The code snippet is:
fileobj = StringIO(attach)
if attach_type == 'application/x-tgz' or attach_type ==
'application/x-tbz' or attach_type == 'application/x-tar':
print '%s file detected, attempting to decompress' %
(attach_type)
tar_archive = tarfile.open('', 'r', fileobj)
print tar_archive.getnames()
for archive_file in tar_archive.getmembers():
print archive_file
print tar_archive.extractfile(archive_file).read()
#except:
# print 'Error while extracting %s.' % (attach_type)
# return ''
I'm at my wits end with this error, it doesn't make any sense that it
would treat bzip2'd tar archives very differently than gz'd tar
archives.
Justin 3 2722
On 26 Aug 2005 09:05:29 -0700, ju**************@gmail.com said: Hello everyone,
I need some tar functionality for my program. Currently the following code properly displays tar archives, and tar.gz archives. However, it chokes on tar.bz2 archives with the following error:
File "mail_filter.py", line 262, in extract_archive tar_archive = tarfile.open('', 'r', fileobj) File "/usr/lib/python2.3/tarfile.py", line 900, in open return func(name, "r", fileobj) File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open raise ValueError, "no support for external file objects" ValueError: no support for external file objects
The code snippet is:
fileobj = StringIO(attach)
if attach_type == 'application/x-tgz' or attach_type == 'application/x-tbz' or attach_type == 'application/x-tar': print '%s file detected, attempting to decompress' % (attach_type)
tar_archive = tarfile.open('', 'r', fileobj)
print tar_archive.getnames() for archive_file in tar_archive.getmembers(): print archive_file print tar_archive.extractfile(archive_file).read() #except: # print 'Error while extracting %s.' % (attach_type) # return ''
Try opening with the 'r:bz2' mode instead of just 'r'.
Cheers,
Richard
r is supposed to autodetect the archive type.
However, even changing it to 'r:bz2' produces an identical error.
On Fri, 26 Aug 2005 09:05:29 -0700, justin.vanwinkle wrote: Hello everyone,
I need some tar functionality for my program. Currently the following code properly displays tar archives, and tar.gz archives. However, it chokes on tar.bz2 archives with the following error:
File "mail_filter.py", line 262, in extract_archive tar_archive = tarfile.open('', 'r', fileobj) File "/usr/lib/python2.3/tarfile.py", line 900, in open return func(name, "r", fileobj) File "/usr/lib/python2.3/tarfile.py", line 980, in bz2open raise ValueError, "no support for external file objects" ValueError: no support for external file objects
The problem here is that the bz2.BZ2File class that tarfile.py uses to
access tar.bz2 files has no support for an external file-object argument.
In contrast to gzip.GzipFile, it works solely on real files.
This limitation is somewhat annoying, but so far no one took the trouble
changing the bz2 module.
If your program does not rely on random access to the tar.bz2 file, you
can still use the "r|bz2" stream mode:
tar_archive = tarfile.open(mode="r|bz2", fileobj=StringIO.StringIO(attach))
for tarinfo in tar_archive:
print tarinfo.name
print tar_archive.extractfile(tarinfo).read()
tar_archive.close()
--
Lars Gustäbel la**@gustaebel.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hans-Joachim Widmaier |
last post by:
Although I've done a bit of ranting before on this, noone seems to have
noticed. I'll try again, hopefully more to the point.
One of the additions in the standard library I liked most is the...
|
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 ' +...
|
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...
|
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...
|
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...
|
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 =...
|
by: Anurag |
last post by:
Hi,
I am trying to use tarfile module to list contents of a 'gz' file but
it seems to hang for large files and CPU usage goes 100%.
though 'tar -tvf' on same file list contents in couple of...
|
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...
|
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,...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |