can python-requests fetch url directly to file handle on disk like curl?
Question: curl has an option to directly save file and header data on disk:

    
    
    curl_setopt($curl_obj, CURLOPT_WRITEHEADER, $header_handle);
    curl_setopt($curl_obj, CURLOPT_FILE, $file_handle);
    

Is there same ability in python-requests ?


Answer: As far as I know, _requests_ does not provide a function that save content to
a file.

    
    
    import requests
    
    with open('local-file', 'wb') as f:
        r = requests.get('url', stream=True)
        f.writelines(r.iter_content(1024))
    

See [request.Response.iter_content documentation](http://www.python-
requests.org/en/latest/api.html#requests.Response.iter_content).

> iter_content(chunk_size=1, decode_unicode=False)
>
> Iterates over the response data. When **stream=True** is set on the request,
> this avoids reading the content at once into memory for large responses. The
> chunk size is the number of bytes it should read into memory. This is not
> necessarily the length of each item returned as decoding can take place.

