Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion TWLight/users/helpers/editor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@

logger = logging.getLogger(__name__)

# Wikimedia's User-Agent policy requires a descriptive User-Agent with contact
# information; the generic Python-urllib default is blocked with HTTP 403.
# https://meta.wikimedia.org/wiki/User-Agent_policy
# The environment (local/staging/production) is included so Wikimedia can
# distinguish development and staging traffic from production.
TWLIGHT_USER_AGENT = "TWLight/1.0 ({env}; https://wikipedialibrary.wmflabs.org/; {contact}) Python-urllib".format(
env=settings.TWLIGHT_ENV or "unknown",
contact=os.environ.get("TWLIGHT_ERROR_MAILTO", "[email protected]"),
)


def editor_global_userinfo(wp_sub: int):
"""
Expand Down Expand Up @@ -63,7 +73,8 @@ def _get_user_info_request(wp_param_name: str, wp_param: str):
query = "{endpoint}?action=query&meta=globaluserinfo&{wp_param_name}={wp_param}&guiprop=editcount|merged&format=json&formatversion=2".format(
endpoint=endpoint, wp_param_name=wp_param_name, wp_param=wp_param
)
return json.loads(urllib.request.urlopen(query).read())
request = urllib.request.Request(query, headers={"User-Agent": TWLIGHT_USER_AGENT})
return json.loads(urllib.request.urlopen(request).read())


def editor_reg_date(identity: dict, global_userinfo: dict):
Expand Down
Loading