import requests

def get_commons_license(filename):
    """
    Look up the declared license for a file on Wikimedia Commons.
    filename should be the bare name, e.g. "Tour Eiffel, Paris.JPG" —
    no URL, no "File:" prefix.
    """
    url = "https://commons.wikimedia.org/w/api.php"
    params = {
        "action": "query",
        "titles": f"File:{filename}",
        "prop": "imageinfo",
        "iiprop": "extmetadata",
        "format": "json",
    }
    # Wikimedia's API etiquette policy rejects the plain default
    # requests User-Agent outright (HTTP 403) -- a descriptive one
    # is not optional here, the way it is for some APIs.
    headers = {"User-Agent": "GLAMWalkTeachingExample/1.0 (https://soretruth.com; teaching example)"}
    response = requests.get(url, params=params, headers=headers, timeout=15)
    response.raise_for_status()
    data = response.json()

    pages = data.get("query", {}).get("pages", {})
    for page in pages.values():
        imageinfo = page.get("imageinfo")
        if not imageinfo:
            continue
        metadata = imageinfo[0].get("extmetadata", {})
        license_field = metadata.get("LicenseShortName", {})
        return license_field.get("value", "UNKNOWN")

    return "UNKNOWN"

print(get_commons_license("Tour Eiffel, Paris.JPG"))