Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
Add timeouts (#104)
Browse files Browse the repository at this point in the history
* Prevent requests blocking

* Version bump to 0.9.1
  • Loading branch information
balloob authored Mar 1, 2017
1 parent 170579e commit 926e487
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions netdisco/philips_hue_nupnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):
def scan(self):
"""Scan the network."""
try:
response = requests.get(self.PHUE_NUPNP_URL)
response = requests.get(self.PHUE_NUPNP_URL, timeout=5)
response.raise_for_status()
self.entries = []
bridges = response.json()
Expand All @@ -63,7 +63,7 @@ def fetch_description(self, bridge):
"""Fetches description XML of a Philips Hue bridge."""
url = self.bridge_description_url(bridge)
try:
response = requests.get(url)
response = requests.get(url, timeout=5)
response.raise_for_status()
return PHueBridge(response.text)
except requests.exceptions.RequestException as err:
Expand Down
8 changes: 4 additions & 4 deletions netdisco/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ def description(self):

if url not in UPNPEntry.DESCRIPTION_CACHE:
try:
xml = requests.get(url).text
xml = requests.get(url, timeout=5).text
if not xml:
# Samsung Smart TV sometimes returns an empty document the
# first time. Retry once.
xml = requests.get(url).text
xml = requests.get(url, timeout=5).text

tree = ElementTree.fromstring(xml)

UPNPEntry.DESCRIPTION_CACHE[url] = \
etree_to_dict(tree).get('root', {})
except requests.RequestException:
logging.getLogger(__name__).error(
logging.getLogger(__name__).warning(
"Error fetching description at %s", url)

UPNPEntry.DESCRIPTION_CACHE[url] = {}

except ElementTree.ParseError:
logging.getLogger(__name__).error(
logging.getLogger(__name__).warning(
"Found malformed XML at %s: %s", url, xml)

UPNPEntry.DESCRIPTION_CACHE[url] = {}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name='netdisco',
version='0.9.0',
version='0.9.1',
description='Discover devices on your local network',
url='https://github.com/home-assistant/netdisco',
author='Paulus Schoutsen',
Expand Down

0 comments on commit 926e487

Please sign in to comment.