Skip to content

Commit 16f782d

Browse files
authored
Merge pull request #422 from rcorex/fix-http-timeout
Add timeout to HTTP requests
2 parents 944da7a + 50af390 commit 16f782d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

resources/lib/jellyfin.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def get(self, path):
3737

3838
url = '{}{}'.format(self.server, path)
3939

40-
r = requests.get(url, headers=self.headers, verify=self.verify_cert)
4140
try:
41+
r = requests.get(url, headers=self.headers, verify=self.verify_cert, timeout=(5,60))
4242
try:
4343
'''
4444
The requests library defaults to using simplejson to handle
@@ -51,7 +51,7 @@ def get(self, path):
5151
response_data = json.loads(r.text)
5252
except ValueError:
5353
response_data = r.json()
54-
except: # noqa
54+
except Exception:
5555
response_data = {}
5656
return response_data
5757

@@ -61,14 +61,14 @@ def post(self, url, payload={}):
6161

6262
url = '{}{}'.format(self.server, url)
6363

64-
r = requests.post(url, json=payload, headers=self.headers, verify=self.verify_cert)
6564
try:
65+
r = requests.post(url, json=payload, headers=self.headers, verify=self.verify_cert, timeout=5)
6666
try:
6767
# Much faster on low power devices, see above comment
6868
response_data = json.loads(r.text)
6969
except ValueError:
7070
response_data = r.json()
71-
except: # noqa
71+
except Exception:
7272
response_data = {}
7373
return response_data
7474

@@ -78,7 +78,10 @@ def delete(self, url):
7878

7979
url = '{}{}'.format(self.server, url)
8080

81-
requests.delete(url, headers=self.headers, verify=self.verify_cert)
81+
try:
82+
requests.delete(url, headers=self.headers, verify=self.verify_cert, timeout=5)
83+
except Exception:
84+
pass
8285

8386
def authenticate(self, auth_data):
8487
# Always force create fresh headers during authentication

0 commit comments

Comments
 (0)