I am not sure, but you could evtl. try 'Session' instead of 'session' to keep-alive: like in the docs https://requests.readthedocs.io/en/latest/user/advanced/#keep-alive
if __name__ == "__main__":
with requests.Session() as s:
res = s.post(login_url, data=login_data)
download_file(s)