Add a global timeout value.
This commit is contained in:
parent
5b0b720a45
commit
46fa6cc63e
|
@ -3,8 +3,10 @@ from urllib.parse import urlencode
|
||||||
from flask import current_app, session
|
from flask import current_app, session
|
||||||
from requests_oauthlib import OAuth1Session
|
from requests_oauthlib import OAuth1Session
|
||||||
|
|
||||||
wiki_hostname = "en.wikipedia.org"
|
WIKI_HOSTNAME = "en.wikipedia.org"
|
||||||
api_url = f"https://{wiki_hostname}/w/api.php"
|
API_URL = f"https://{WIKI_HOSTNAME}/w/api.php"
|
||||||
|
|
||||||
|
TIMEOUT = 20
|
||||||
|
|
||||||
|
|
||||||
def get_edit_proxy() -> dict[str, str]:
|
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"],
|
resource_owner_secret=session["owner_secret"],
|
||||||
)
|
)
|
||||||
proxies = get_edit_proxy()
|
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):
|
def raw_request(params):
|
||||||
app = current_app
|
app = current_app
|
||||||
url = api_url + "?" + urlencode(params)
|
url = API_URL + "?" + urlencode(params)
|
||||||
client_key = app.config["CLIENT_KEY"]
|
client_key = app.config["CLIENT_KEY"]
|
||||||
client_secret = app.config["CLIENT_SECRET"]
|
client_secret = app.config["CLIENT_SECRET"]
|
||||||
oauth = OAuth1Session(
|
oauth = OAuth1Session(
|
||||||
|
@ -43,7 +45,7 @@ def raw_request(params):
|
||||||
resource_owner_secret=session["owner_secret"],
|
resource_owner_secret=session["owner_secret"],
|
||||||
)
|
)
|
||||||
proxies = get_edit_proxy()
|
proxies = get_edit_proxy()
|
||||||
return oauth.get(url, timeout=10, proxies=proxies)
|
return oauth.get(url, timeout=TIMEOUT, proxies=proxies)
|
||||||
|
|
||||||
|
|
||||||
def api_request(params):
|
def api_request(params):
|
||||||
|
|
Loading…
Reference in a new issue