response = requests.request("GET", url, headers=headers, params=querystring) with open(response.headers['Content-Disposition'].split("filename=")[1], 'w', encoding='utf-8') as f: print(response.text, file=f)