Bruno Caetano Bruno Caetano - 2 months ago 6x
Python Question

Retrieve image from method called by URL in python

I'm trying to retrieve an image that is returned through a given URL using python, for example this one:

I am trying to do this by using urllib retrieve method:

import urllib

urlStr = ""
filename = "image.png"

I already used this for other URLs, (such as, but for the first one it's not working.

Does anyone have an idea about how to make this for the given URL?
Note: I'm using Python 2.7


You need to use a session which you can do with requests:

import requests

with requests.Session() as s:
    with open("out.png", "wb") as f:

It works in your browser as you had visited the initial page where the image was so any necessary cookies were set.