Here is what I have:
compressionLevel = 9
source_file = '/foo/bar.txt' #this file can be in a different format, like .csv or others...
destination_file = '/foo/bar.bz2'
tarbz2contents = bz2.compress(source_file, compressionLevel)
fh = open(destination_file, "wb")
The documentation for bz2.compress for says it takes data, not a file name.
Try replacing the line below:
tarbz2contents = bz2.compress(open(source_file, 'rb').read(), compressionLevel)
...or maybe :
with open(source_file, 'rb') as data: tarbz2contents = bz2.compress(data, compressionLevel)