Tarfile Can't Open Tgz
I am trying to download tgz file from this website: https://plg.uwaterloo.ca/cgi-bin/cgiwrap/gvcormac/foo07 here is my script: import os from six.moves import urllib import tarfile
Solution 1:
You can add additional parameters to tarfile.open
. You need to set the mode to 'r:gz'
.
tarfile.open(path, 'r:gz')
Working example after Accept Agreement:
import tarfile
import requests
URL = 'https://plg.uwaterloo.ca/cgi-bin/cgiwrap/gvcormac/trec07p.tgz'
FILE = '/home/blake/Downloads/trec07p.tgz'
resp = requests.get(URL, stream=True)
resp.raise_for_status()
withopen(FILE, 'wb') as out_file:
for line in resp.iter_content(chunk_size=1024*4, decode_unicode=False):
out_file.write(line)
f = tarfile.open(FILE, 'r:gz')
print(f.getnames())
f.close()
Output:
['trec07p/data/inmail.35059',
'trec07p/data/inmail.34430',
'trec07p/data/inmail.45722',
..
..]
Post a Comment for "Tarfile Can't Open Tgz"