From 420702e7cfe0885c651dbfba3bcc139f7682cf7a Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 5 Dec 2022 14:59:24 +0700 Subject: [PATCH] add requests timeout --- tubearchivist/web/src/webhook_github.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tubearchivist/web/src/webhook_github.py b/tubearchivist/web/src/webhook_github.py index cc37db1..9a20525 100644 --- a/tubearchivist/web/src/webhook_github.py +++ b/tubearchivist/web/src/webhook_github.py @@ -308,7 +308,7 @@ class GithubBackup: def ingest_build_line(self): """ingest latest release into postgres""" - response = requests.get(self.URL + self.tag) + response = requests.get(self.URL + self.tag, timeout=10) if not response.ok: print(response.text) raise ValueError @@ -424,7 +424,7 @@ class RoadmapHook: user = self.repo_conf.get("gh_user") repo = self.repo_conf.get("gh_repo") url = f"https://api.github.com/repos/{user}/{repo}/contents/README.md" - response = requests.get(url).json() + response = requests.get(url, timeout=10).json() content = base64.b64decode(response["content"]).decode() paragraphs = [i.strip() for i in content.split("##")] for paragraph in paragraphs: @@ -452,7 +452,7 @@ class RoadmapHook: def delete_webhook(self, message_id): """delete old message""" url = f"{self.hook_url}/messages/{message_id}" - response = requests.delete(url) + response = requests.delete(url, timeout=10) print(response) def send_message(self): @@ -468,7 +468,9 @@ class RoadmapHook: "color": 10555 }] } - response = requests.post(f"{self.hook_url}?wait=true", json=data) + response = requests.post( + f"{self.hook_url}?wait=true", json=data, timeout=10 + ) print(response) print(response.text) @@ -521,14 +523,14 @@ class EsVersionSync: def get_expected(self): """get expected es version from readme""" - response = requests.get(self.COMPOSE).json() + response = requests.get(self.COMPOSE, timeout=10).json() content = base64.b64decode(response["content"]).decode() line = [i for i in content.split("\n") if self.IMAGE in i][0] self.expected = line.split()[-1] def get_current(self): """get current version from docker hub""" - response = requests.get(self.TAGS).json() + response = requests.get(self.TAGS, timeout=10).json() all_tags = [i.get("name") for i in response["results"]] all_tags.pop(0) all_tags.sort()