You are receiving a string value, one that json.loads() could turn into Python objects. To save that response to a file, do not encode, do not decode, just save it straight to the file object. The most efficient way would be to use shutil.copyfileobj():