From 306fc202bdcbfca466fc1bec37ba9916bab093df Mon Sep 17 00:00:00 2001 From: Taizo Simpson Date: Wed, 31 Oct 2018 13:20:38 -0400 Subject: [PATCH] Add a timeout when fetching remote resources --- supysonic/api/media.py | 2 +- supysonic/lastfm.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/supysonic/api/media.py b/supysonic/api/media.py index a7aa68e..52533fc 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -201,7 +201,7 @@ def lyrics(): try: r = requests.get("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect", - params = { 'artist': artist, 'song': title }) + params = { 'artist': artist, 'song': title }, timeout = 5) root = ElementTree.fromstring(r.content) ns = { 'cl': 'http://api.chartlyrics.com/' } diff --git a/supysonic/lastfm.py b/supysonic/lastfm.py index e74a8e7..bd803a2 100644 --- a/supysonic/lastfm.py +++ b/supysonic/lastfm.py @@ -77,9 +77,9 @@ class LastFm: try: if write: - r = requests.post('http://ws.audioscrobbler.com/2.0/', data = kwargs) + r = requests.post('http://ws.audioscrobbler.com/2.0/', data = kwargs, timeout = 5) else: - r = requests.get('http://ws.audioscrobbler.com/2.0/', params = kwargs) + r = requests.get('http://ws.audioscrobbler.com/2.0/', params = kwargs, timeout = 5) except requests.exceptions.RequestException as e: self.__logger.warning('Error while connecting to LastFM: ' + str(e)) return None