Add a global timeout value.

This commit is contained in:
Edward Betts 2022-08-18 20:49:22 +01:00
parent 5b0b720a45
commit 46fa6cc63e

View file

@ -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):