Allow edit via proxy to avoid global IP block

This commit is contained in:
Edward Betts 2020-04-22 16:44:04 +01:00
parent e903c4092f
commit 6194874380

View file

@ -2,6 +2,13 @@ from flask import current_app, session
from requests_oauthlib import OAuth1Session
from urllib.parse import urlencode
def get_edit_proxy():
edit_proxy = current_app.config.get('EDIT_PROXY')
if edit_proxy:
return {'http': edit_proxy, 'https': edit_proxy}
else:
return {}
def api_post_request(params):
app = current_app
url = 'https://www.wikidata.org/w/api.php'
@ -11,7 +18,8 @@ def api_post_request(params):
client_secret=client_secret,
resource_owner_key=session['owner_key'],
resource_owner_secret=session['owner_secret'])
return oauth.post(url, data=params, timeout=4)
proxies = get_edit_proxy()
return oauth.post(url, data=params, timeout=4, proxies=proxies)
def raw_request(params):
app = current_app
@ -22,7 +30,8 @@ def raw_request(params):
client_secret=client_secret,
resource_owner_key=session['owner_key'],
resource_owner_secret=session['owner_secret'])
return oauth.get(url, timeout=4)
proxies = get_edit_proxy()
return oauth.get(url, timeout=4, proxies=proxies)
def api_request(params):
return raw_request(params).json()