From 591b7751b1e0eb851e2a059dadc6003dac2c82db Mon Sep 17 00:00:00 2001 From: tinytap Date: Wed, 3 Mar 2021 10:47:45 +0200 Subject: [PATCH] add timeout to requests --- detectlanguage/client.py | 4 ++-- detectlanguage/configuration.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/detectlanguage/client.py b/detectlanguage/client.py index fa0f6d5..999ca45 100644 --- a/detectlanguage/client.py +++ b/detectlanguage/client.py @@ -13,11 +13,11 @@ def __init__(self, configuration): self.configuration = configuration def get(self, path, payload = {}): - r = requests.get(self.url(path), params=payload, headers = self.headers()) + r = requests.get(self.url(path), params=payload, headers = self.headers(), timeout = self.configuration.timeout) return self.handle_response(r) def post(self, path, payload): - r = requests.post(self.url(path), json=payload, headers = self.headers()) + r = requests.post(self.url(path), json=payload, headers = self.headers(), timeout = self.configuration.timeout) return self.handle_response(r) def handle_response(self, r): diff --git a/detectlanguage/configuration.py b/detectlanguage/configuration.py index bd73c3f..2fb0482 100644 --- a/detectlanguage/configuration.py +++ b/detectlanguage/configuration.py @@ -6,3 +6,4 @@ class Configuration: host = 'ws.detectlanguage.com' user_agent = 'Detect Language API Python Client ' + detectlanguage.__version__ secure = False + timeout = 5