Adjust logging in downloader component (#10622)
This commit is contained in:
parent
5c20cc32b5
commit
24aeea5ca3
1 changed files with 8 additions and 3 deletions
|
@ -77,8 +77,13 @@ def setup(hass, config):
|
||||||
|
|
||||||
req = requests.get(url, stream=True, timeout=10)
|
req = requests.get(url, stream=True, timeout=10)
|
||||||
|
|
||||||
if req.status_code == 200:
|
if req.status_code != 200:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"downloading '%s' failed, stauts_code=%d",
|
||||||
|
url,
|
||||||
|
req.status_code)
|
||||||
|
|
||||||
|
else:
|
||||||
if filename is None and \
|
if filename is None and \
|
||||||
'content-disposition' in req.headers:
|
'content-disposition' in req.headers:
|
||||||
match = re.findall(r"filename=(\S+)",
|
match = re.findall(r"filename=(\S+)",
|
||||||
|
@ -121,13 +126,13 @@ def setup(hass, config):
|
||||||
|
|
||||||
final_path = "{}_{}.{}".format(path, tries, ext)
|
final_path = "{}_{}.{}".format(path, tries, ext)
|
||||||
|
|
||||||
_LOGGER.info("%s -> %s", url, final_path)
|
_LOGGER.debug("%s -> %s", url, final_path)
|
||||||
|
|
||||||
with open(final_path, 'wb') as fil:
|
with open(final_path, 'wb') as fil:
|
||||||
for chunk in req.iter_content(1024):
|
for chunk in req.iter_content(1024):
|
||||||
fil.write(chunk)
|
fil.write(chunk)
|
||||||
|
|
||||||
_LOGGER.info("Downloading of %s done", url)
|
_LOGGER.debug("Downloading of %s done", url)
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.exception("ConnectionError occurred for %s", url)
|
_LOGGER.exception("ConnectionError occurred for %s", url)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue