From aa51c9185174fbf8192472cc51a1ce16893f51f7 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Mon, 21 Aug 2023 08:34:06 +0300 Subject: [PATCH] add timeout --- antp/ankiconnect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/antp/ankiconnect.py b/antp/ankiconnect.py index 2d21e9b..9c7278d 100644 --- a/antp/ankiconnect.py +++ b/antp/ankiconnect.py @@ -16,7 +16,10 @@ def request(action, **params): def invoke(action, **params): request_json = json.dumps(request(action, **params)).encode('utf-8') - response = json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8765', request_json))) + response = json.load(urllib.request.urlopen( + urllib.request.Request('http://127.0.0.1:8765', request_json), + timeout=10 + )) if len(response) != 2: raise ANTPError('response has an unexpected number of fields') if 'error' not in response: