Don't attempt thumbnail download when we receive an error HTTP code
This commit is contained in:
parent
5c2beaf7b2
commit
6bf8300948
@ -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
|
# Separated doing the GET and downloading the body of the GET, so that we can cancel
|
||||||
# the download in between.
|
# the download in between.
|
||||||
|
|
||||||
def perform_get_request():
|
def perform_get_request() -> requests.Request:
|
||||||
return uncached_session.get(url, stream=True, verify=True)
|
return uncached_session.get(url, stream=True, verify=True)
|
||||||
|
|
||||||
# Download the file in a different thread.
|
# Download the file in a different thread.
|
||||||
def download_loop():
|
def download_loop():
|
||||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||||
|
|
||||||
with closing(req), open(filename, 'wb') as outfile:
|
with closing(response), open(filename, 'wb') as outfile:
|
||||||
for block in req.iter_content(chunk_size=chunk_size):
|
for block in response.iter_content(chunk_size=chunk_size):
|
||||||
if is_cancelled(future):
|
if is_cancelled(future):
|
||||||
raise asyncio.CancelledError('Downloading was cancelled')
|
raise asyncio.CancelledError('Downloading was cancelled')
|
||||||
outfile.write(block)
|
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')
|
raise asyncio.CancelledError('Downloading was cancelled')
|
||||||
|
|
||||||
log.debug('Performing GET %s', url)
|
log.debug('Performing GET %s', url)
|
||||||
req = await loop.run_in_executor(None, perform_get_request)
|
response = await loop.run_in_executor(None, perform_get_request)
|
||||||
log.debug('Done with GET %s', url)
|
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
|
# After we performed the GET request, we should check whether we should start
|
||||||
# the download at all.
|
# the download at all.
|
||||||
|
Reference in New Issue
Block a user