Add timeout for requests
This commit is contained in:
parent
f21d97d5a2
commit
53b43dc4db
1 changed files with 4 additions and 3 deletions
|
@ -53,7 +53,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
try:
|
try:
|
||||||
for location in [config.get('from', None), config.get('to', None)]:
|
for location in [config.get('from', None), config.get('to', None)]:
|
||||||
# transport.opendata.ch doesn't play nice with requests.Session
|
# transport.opendata.ch doesn't play nice with requests.Session
|
||||||
result = get(_RESOURCE + 'locations?query=%s' % location)
|
result = get(_RESOURCE + 'locations?query=%s' % location,
|
||||||
|
timeout=10)
|
||||||
journey.append(result.json()['stations'][0]['name'])
|
journey.append(result.json()['stations'][0]['name'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.exception(
|
_LOGGER.exception(
|
||||||
|
@ -115,8 +116,8 @@ class PublicTransportData(object):
|
||||||
'from=' + self.start + '&' +
|
'from=' + self.start + '&' +
|
||||||
'to=' + self.destination + '&' +
|
'to=' + self.destination + '&' +
|
||||||
'fields[]=connections/from/departureTimestamp/&' +
|
'fields[]=connections/from/departureTimestamp/&' +
|
||||||
'fields[]=connections/')
|
'fields[]=connections/',
|
||||||
|
timeout=10)
|
||||||
connections = response.json()['connections'][:2]
|
connections = response.json()['connections'][:2]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue