title: Downloading multiple files with requests in Python
body: <p>Currently im facing following problem:</p>
  
  <p>I have 3 download links in a list. Only the last file in the list is downloaded completely.
  The others have a file size of one kilobyte.</p>
  
  <p>Code:</p>
  
  <pre><code>from requests import get
  
  def download(url, filename):
      with open(filename, "wb") as file:
          response = get(url, stream=True)
          file.write(response.content)
  
  for link in f:
      url = link
      split_url = url.split("/")
      filename = split_url[-1]
      filename = filename.replace("\n", "")
      download(url,filename)
  </code></pre>
  
  <p>The result looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/nbY2r.png" rel="nofollow noreferrer">Result</a></p>
  
  <p>How do I make sure that all files are downloaded correctly?
  All links are direct download links.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I discovered it only happens when I read the links from the .txt</p>
  
  <p>If I create the list in python like this:</p>
  
  <pre><code>links = ["http://ipv4.download.thinkbroadband.com/20MB.zip",
              "http://ipv4.download.thinkbroadband.com/10MB.zip",
              "http://ipv4.download.thinkbroadband.com/5MB.zip"]
  </code></pre>
  
  <p>... the problem doesnt appear.</p>
  
  <p>reproduceable example: </p>
  
  <pre><code>from requests import get
  
  def download(url, filename):
      with open(filename, "wb") as file:
          response = get(url, stream = True)
          file.write(response.content)
  
  f = open('links.txt','r')
  for link in f:
      url = link
      split_url = url.split("/")
      filename = split_url[-1]
      filename = filename.replace("\n", "")
      download(url,filename)
  </code></pre>
  
  <p>content of links.txt:</p>
  
  <pre><code>http://ipv4.download.thinkbroadband.com/20MB.zip
  http://ipv4.download.thinkbroadband.com/10MB.zip
  http://ipv4.download.thinkbroadband.com/5MB.zip
  </code></pre>