title: Python - Download image from direct link (Forbidden, You don't have permission to access on this server)
body: <p>I need to download an image through Python (can't post the url since I think the content type is not allowed here).</p>
  
  <p>The image is loaded in a page, so I first get the image direct url from the page source code with BeautifoulSoup and then try do download it with: </p>
  
  <pre><code>import urllib2
  urllib2.urlretrieve(image, folder)
  </code></pre>
  
  <p>which usually works fine, but it doesn't work on this server.</p>
  
  <p>If I open the page with the image in my browser and then copy the image direct link in another browser window and open it, I get the image, but if I try to directly open the image in another window without first opening the webpage where the image is, I get the error 403: </p>
  
  <blockquote>
    <p><strong>Forbidden</strong> You don't have permission to access /1.jpg on this server.</p>
  </blockquote>
  
  <p>Direct opening the image still works if I close the browser and re-open it, but if I change the browser I get error 403 again. </p>
  
  <p>I thought it could be something cookie-releated, so I've tried:</p>
  
  <pre><code>response = urllib2.urlopen(PAGE_WITH_IMAGE)
  cookie = response.headers.get('Set-Cookie')
  req2 = urllib2.Request(DIRECT_LINK_TO_IMAGE)
  req2.add_header('cookie', cookie)
  urllib2.urlretrieve(req2, folder)
  </code></pre>
  
  <p>But I still get error 403.</p>