from contextlib import closing with closing(requests.get('http://httpbin.org/get', stream=True)) as r: # The response is processed here.