我无法让 tqdm 的下载进度条显示进度

I can't make the download progress bar from tqdm to show the progress

我想用tqdm 添加一个下载进度条。问题是它向我展示了这个:

0%|                                                                           | 0/11535.92578125 [00:00<?, ?KB/s]

它下载文件但没有显示任何进度。这是我的代码:

s = requests.Session()
r = s.post(url, login_data)
response = s.get(link_to_pdf, stream=True)
total_size = int(response.headers['content-length'])
# download the pdf
print(pdf_filename)
with open(pdf_filename + '.pdf', 'wb') as f:
    for data in tqdm(iterable=response.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='KB'):
        f.write(response.content)

你没有写你写请求的数据 1 次不是块,只是替换 response.content 你在从 tqdm

获得的数据链接中写入文件
  with open(pdf_filename + '.pdf', 'wb') as f:
    for data in tqdm(iterable=response.iter_content(chunk_size=chunk_size), total=total_size / chunk_size, unit='KB'):
        f.write(data)