Fix download not always returning entire requests.response object
This commit is contained in:
parent
63bd85d5c8
commit
057921b05e
2 changed files with 12 additions and 12 deletions
|
@ -224,7 +224,11 @@ class DownloadUtils():
|
|||
if r.status_code != 401:
|
||||
self.count_unauthorized = 0
|
||||
|
||||
if r.status_code == 204:
|
||||
if return_response is True:
|
||||
# return the entire response object
|
||||
return r
|
||||
|
||||
elif r.status_code == 204:
|
||||
# No body in the response
|
||||
# But read (empty) content to release connection back to pool
|
||||
# (see requests: keep-alive documentation)
|
||||
|
@ -258,9 +262,6 @@ class DownloadUtils():
|
|||
elif r.status_code in (200, 201):
|
||||
# 200: OK
|
||||
# 201: Created
|
||||
if return_response is True:
|
||||
# return the entire response object
|
||||
return r
|
||||
try:
|
||||
# xml response
|
||||
r = utils.defused_etree.fromstring(r.content)
|
||||
|
|
|
@ -320,16 +320,15 @@ class Media(object):
|
|||
filename,
|
||||
extension)
|
||||
response = DU().downloadUrl(url, return_response=True)
|
||||
try:
|
||||
response.status_code
|
||||
except AttributeError:
|
||||
if not response.ok:
|
||||
LOG.error('Could not temporarily download subtitle %s', url)
|
||||
LOG.error('HTTP status: %s, message: %s',
|
||||
response.status_code, response.text)
|
||||
return
|
||||
else:
|
||||
LOG.debug('Writing temp subtitle to %s', path)
|
||||
with open(path_ops.encode_path(path), 'wb') as f:
|
||||
f.write(response.content)
|
||||
return path
|
||||
LOG.debug('Writing temp subtitle to %s', path)
|
||||
with open(path_ops.encode_path(path), 'wb') as f:
|
||||
f.write(response.content)
|
||||
return path
|
||||
|
||||
def validate_playurl(self, path, typus, force_check=False, folder=False,
|
||||
omit_check=False):
|
||||
|
|
Loading…
Reference in a new issue