From 6bf8300948c93a0acf943fbeb38f9566f52dd2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 21 Mar 2016 11:47:29 +0100 Subject: [PATCH] Don't attempt thumbnail download when we receive an error HTTP code --- blender_cloud/pillar.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/blender_cloud/pillar.py b/blender_cloud/pillar.py index fbf2fac..7fc396e 100644 --- a/blender_cloud/pillar.py +++ b/blender_cloud/pillar.py @@ -145,15 +145,15 @@ async def download_to_file(url, filename, chunk_size=100 * 1024, *, future: asyn # Separated doing the GET and downloading the body of the GET, so that we can cancel # the download in between. - def perform_get_request(): + def perform_get_request() -> requests.Request: return uncached_session.get(url, stream=True, verify=True) # Download the file in a different thread. def download_loop(): os.makedirs(os.path.dirname(filename), exist_ok=True) - with closing(req), open(filename, 'wb') as outfile: - for block in req.iter_content(chunk_size=chunk_size): + with closing(response), open(filename, 'wb') as outfile: + for block in response.iter_content(chunk_size=chunk_size): if is_cancelled(future): raise asyncio.CancelledError('Downloading was cancelled') outfile.write(block) @@ -164,8 +164,9 @@ async def download_to_file(url, filename, chunk_size=100 * 1024, *, future: asyn raise asyncio.CancelledError('Downloading was cancelled') log.debug('Performing GET %s', url) - req = await loop.run_in_executor(None, perform_get_request) - log.debug('Done with GET %s', url) + response = await loop.run_in_executor(None, perform_get_request) + log.debug('Status %i from GET %s', response.status_code, url) + response.raise_for_status() # After we performed the GET request, we should check whether we should start # the download at all.