On 26 Aug 2005 09:05:29 -0700, [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list