From 46fa6cc63e673704a3e04993366122e8c6be2fbb Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 18 Aug 2022 20:49:22 +0100 Subject: [PATCH] Add a global timeout value. --- dab_mechanic/wikidata_oauth.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dab_mechanic/wikidata_oauth.py b/dab_mechanic/wikidata_oauth.py index 5af0976..5b048b2 100644 --- a/dab_mechanic/wikidata_oauth.py +++ b/dab_mechanic/wikidata_oauth.py @@ -3,8 +3,10 @@ from urllib.parse import urlencode from flask import current_app, session from requests_oauthlib import OAuth1Session -wiki_hostname = "en.wikipedia.org" -api_url = f"https://{wiki_hostname}/w/api.php" +WIKI_HOSTNAME = "en.wikipedia.org" +API_URL = f"https://{WIKI_HOSTNAME}/w/api.php" + +TIMEOUT = 20 def get_edit_proxy() -> dict[str, str]: @@ -28,12 +30,12 @@ def api_post_request(params: dict[str, str | int]): resource_owner_secret=session["owner_secret"], ) proxies = get_edit_proxy() - return oauth.post(api_url, data=params, timeout=10, proxies=proxies) + return oauth.post(API_URL, data=params, timeout=TIMEOUT, proxies=proxies) def raw_request(params): app = current_app - url = api_url + "?" + urlencode(params) + url = API_URL + "?" + urlencode(params) client_key = app.config["CLIENT_KEY"] client_secret = app.config["CLIENT_SECRET"] oauth = OAuth1Session( @@ -43,7 +45,7 @@ def raw_request(params): resource_owner_secret=session["owner_secret"], ) proxies = get_edit_proxy() - return oauth.get(url, timeout=10, proxies=proxies) + return oauth.get(url, timeout=TIMEOUT, proxies=proxies) def api_request(params):