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

Commit 926e487

Browse files
authored
Add timeouts (#104)
* Prevent requests blocking * Version bump to 0.9.1
1 parent 170579e commit 926e487

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

netdisco/philips_hue_nupnp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self):
4646
def scan(self):
4747
"""Scan the network."""
4848
try:
49-
response = requests.get(self.PHUE_NUPNP_URL)
49+
response = requests.get(self.PHUE_NUPNP_URL, timeout=5)
5050
response.raise_for_status()
5151
self.entries = []
5252
bridges = response.json()
@@ -63,7 +63,7 @@ def fetch_description(self, bridge):
6363
"""Fetches description XML of a Philips Hue bridge."""
6464
url = self.bridge_description_url(bridge)
6565
try:
66-
response = requests.get(url)
66+
response = requests.get(url, timeout=5)
6767
response.raise_for_status()
6868
return PHueBridge(response.text)
6969
except requests.exceptions.RequestException as err:

netdisco/ssdp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,24 @@ def description(self):
128128

129129
if url not in UPNPEntry.DESCRIPTION_CACHE:
130130
try:
131-
xml = requests.get(url).text
131+
xml = requests.get(url, timeout=5).text
132132
if not xml:
133133
# Samsung Smart TV sometimes returns an empty document the
134134
# first time. Retry once.
135-
xml = requests.get(url).text
135+
xml = requests.get(url, timeout=5).text
136136

137137
tree = ElementTree.fromstring(xml)
138138

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

145145
UPNPEntry.DESCRIPTION_CACHE[url] = {}
146146

147147
except ElementTree.ParseError:
148-
logging.getLogger(__name__).error(
148+
logging.getLogger(__name__).warning(
149149
"Found malformed XML at %s: %s", url, xml)
150150

151151
UPNPEntry.DESCRIPTION_CACHE[url] = {}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33
setup(name='netdisco',
4-
version='0.9.0',
4+
version='0.9.1',
55
description='Discover devices on your local network',
66
url='https://github.com/home-assistant/netdisco',
77
author='Paulus Schoutsen',

0 commit comments

Comments
 (0)