I'm trying to quickly download kali-linux live-amd64.iso.torrent file from kali.org/downloads using requests, and bs4, but in the headers of the torrent response, there is no: response.headers['content-disposition']
My reference was from: How to download a file with .torrent extension from link with Python. I looked into the headers of the torrent_response, and this is what came up:
{'Server': 'nginx/1.14.2', 'Date': 'Thu, 08 Apr 2021 07:46:17 GMT', 'Content-Type': 'application/octet-stream', 'Content-Length': '274612', 'Connection': 'keep-alive', 'Last-Modified': 'Wed, 24 Feb 2021 17:39:18 GMT', 'ETag': '"60368f46-430b4"', 'X-Cache-Status': 'HIT', 'Accept-Ranges': 'bytes'}
class Download_Kali:
def __init__(self, locator):
self.locator = locator
def locate_torrent(self):
torrent_links = [torrent['href'] for torrent in self.locator.findAll('a', string='Torrent')]
for live_iso in torrent_links:
if 'live-amd64' in live_iso:
print('[*] Downloading iso Torrent')
return live_iso
def install(self):
import re, traceback
try:
with requests.get(Download_Kali(self.locator).locate_torrent()) as torrent_response:
torrent_response.raise_for_status()
disposition = torrent_response.headers
print(disposition)
#torrent_file = re.findall('filename="(.+)"', disposition)
#if torrent_file:
# with open(torrent_file[0], 'wb') as f_torrent:
# f_torrent.write(torrent_response.content)
except requests.HTTPError as err:
print(traceback.format_exc())