title: Python - download a file that needs a cookie set
body: <p>I have the following code</p>
  
  <p>import urllib</p>
  
  <pre><code>f=open('ondemand.txt','r')
  for line in f:
      urllib.urlretrieve (line, "1.webm")
  </code></pre>
  
  <p>In theory, it works, but the URLs need a cookie set. How would I go about it in the above scenario or do I need to move to <code>urllib2</code> or <code>requests</code>?</p>
  
  <p>I have tried using requests as follows:</p>
  
  <pre><code>import requests
  f=open('ondemand.txt','r')
  cookie = {'nameofcookie': 'valueofcookie'}
  for line in f:
      response = requests.get(line,cookies=cookie)
      print response.text
      fName =  line.split('/')[-1]    
      with open('/tmp/'+fName, 'wb') as f:
          f.write(response.content)
  </code></pre>
  
  <p>However I get the error:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;Error&gt;
          &lt;Code&gt;MissingKey&lt;/Code&gt;
              &lt;Message&gt;Missing Key-Pair-Id query parameter or cookie value&lt;/Message&gt;
      &lt;/Error&gt;
  </code></pre>
  
  <p>Thanks</p>