By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,400 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,400 IT Pros & Developers. It's quick & easy.

Tarfile module error

P: n/a

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\", line 8, in ?
TarFileBackup =, 'w:bz2')
File "C:\Python23\lib\", line 875, in open
return func(name, filemode, fileobj)
File "C:\Python23\lib\", line 980, in bz2open
raise ReadError, "not a bzip2 file"
tarfile.ReadError: not a bzip2 file
Here's the code:
import tarfile
from datetime import datetime

DirBackup = r'\\skpdc01\Backups'
DirOrig = r'C:\WUTemp'

NewBackupFilename = DirBackup + '\\' + '%s' % ( +
TarFileBackup =, 'w:bz2')
What am I doing wrong? From the error message I gues the library is
expecting the bzip file to exists, but I am explicitly open it whit
'w:bz2' Any ideas?

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Your NewBackupFilename contains ":" which is not a valid character in a
filename in Windows.

You could do something like this:
NewBackupFilename = DirBackup + '\\' + '%s' % str(':', '-') + '.tar.bz2' NewBackupFilename 'c:\\\\skpdc01\\\\Backups\\2005-01-21 12-26-21.373000.tar.bz2' TarFileBackup =, 'w:bz2')
# Works!

I changed your DirBackup to 'C:\skpdc01\Backups'


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.