0

I am downloading some files from the FAO GAEZ database, which uses HTTP POST based login from.
I am thus using the requests module. Here is my code:

my_user = "blabla"
my_pass = "bleble"
site_url = "http://www.gaez.iiasa.ac.at/w/ctrl?_flow=Vwr&_view=Welcome&fieldmain=main_lr_lco_cult&idPS=0&idAS=0&idFS=0"
file_url = "http://www.gaez.iiasa.ac.at/w/ctrl?_flow=VwrServ&_view=AAGrid&idR=m1ed3ed864793f16e83ba9a5a975066adaa6bf1b0" 

with requests.Session() as s:
    s.get(site_url)
    s.post(site_url, data={'_username': 'my_user', '_password': 'my_pass'})
    r = s.get(file_url)    
    if r.ok:
        with open(my_path + "\\My file.zip", "wb") as c:
            c.write(r.content)

However, with this procedure I download the HTML of the page.
I suspect that to solve the problem I have to add the name of the zip file to the url, i.e. new_file_url = file_url + "/file_name.zip". The problem is that I don't know the "file_name". I've tried with the name of the file which I obtain when I download it manually, but it does not work.

Any of idea on how to solve this? If you need more details on GAEZ website, see also: Python - Login and download specific file from website

Matteo
  • 1

0 Answers0