From 203a147fad603381284890e40914cf69e9277f75 Mon Sep 17 00:00:00 2001 From: jeancf Date: Fri, 27 Sep 2019 11:44:11 +0200 Subject: [PATCH] Added timeout to request of linked page --- twoot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twoot.py b/twoot.py index be227e4..3e7ff4d 100755 --- a/twoot.py +++ b/twoot.py @@ -216,13 +216,13 @@ def main(argv): if m is not None: link_url = m.group(0) try: - r = requests.get(link_url) + r = requests.get(link_url, timeout=10) if r.status_code == 200: # Matches the first instance of either twitter:image or twitter:image:src meta tag match = re.search(r'', r.text) if match is not None: photos.append(match.group(1)) - except ConnectionError: + except (requests.exceptions.ConnectionError, requests.exceptions.Timeout): pass # Add dictionary with content of tweet to list