title: How to fix error when downloading file in python
body: <p>I have a python script to download ISO files from microsoft, but when it gets to the windows 8.1 through windows 11 ISO downloads, it produces an error and does not download the files</p>
  <p>Here is a screenshot of the error:
  <a href="https://i.stack.imgur.com/r1llG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r1llG.png" alt="enter image description here" /></a></p>
  <p>And here is my current code (Windows 7 ISOs commented out to skip to error):</p>
  <pre><code>import sys
  import requests
  import time
  
  def download_url(link):
      start = time.time()
      file_name_start_pos = link.rfind(&quot;/&quot;) + 1
      file_name = link[file_name_start_pos:]
      with open(file_name, &quot;wb&quot;) as f:
          print(&quot;Downloading %s&quot; % file_name)
          response = requests.get(link, stream=True)
          total_length = response.headers.get('content-length')
          if total_length is None: # no content length header
              f.write(response.content)
          else:
              dl = 0
              total_length = int(total_length)
              for data in response.iter_content(chunk_size=4096):
                  dl += len(data)
                  f.write(data)
                  done = int(50 * dl / total_length)
                  percent = int(100 * dl / total_length)
                  toataltime = time.time() - start
                  sys.stdout.write(&quot;\r[%s%s] &quot; % ('#' * done, ' ' * (50-done))+str(percent)+&quot;% (&quot;+str(dl)+&quot;/&quot;+str(total_length)+&quot;) &quot;+str(round(round((((dl/1024)/1024)*8))/toataltime))+&quot; Mbps Avg&quot;)
                  sys.stdout.flush()
      print(&quot;\n&quot;)
  
  
  #Windows 7 Home
  #download_url(&quot;https://download.microsoft.com/download/E/A/8/EA804D86-C3DF-4719-9966-6A66C9306598/7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_HOMEPREMIUM_x64FRE_en-us.iso&quot;)
  
  #Windows 7 Pro
  #download_url(&quot;https://download.microsoft.com/download/0/6/3/06365375-C346-4D65-87C7-EE41F55F736B/7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_PROFESSIONAL_x64FRE_en-us.iso&quot;)
  
  #Windows 7 Ultimate
  #download_url(&quot;https://download.microsoft.com/download/5/1/9/5195A765-3A41-4A72-87D8-200D897CBE21/7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso&quot;)
  
  #Windows 8.1
  download_url(&quot;https://software-download.microsoft.com/pr/Win8.1_English_x64.iso?t=3f986a33-d055-4091-aa7b-c63192d916ab&amp;&amp;e=1638067997&amp;&amp;h=67f853a7ef459f36f45647c06d2a29a0&quot;)
  
  #Windows 10
  download_url(&quot;https://software-download.microsoft.com/pr/Win10_21H2_English_x64.iso?t=e3833d87-c6a1-409d-af98-aaabfa52a5fe&amp;e=1638068076&amp;h=e1421b879b14b6900da6ec8e6e1ea547&quot;)
  
  #Windows 11
  download_url(&quot;https://software-download.microsoft.com/pr/Win11_English_x64.iso?t=35afe7c0-aac5-497f-96fd-120a6d1ea9e1&amp;e=1638068135&amp;h=41e1d770adde9f4ad56cb2d357b55c61&quot;)
  </code></pre>