[Python] Specify Contact info in Wikipedia User Agent Policy

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to use some Wikipedia images for a Python script, but I came across an error:

    Error: 403 Client Error: Forbidden. Please comply with the User-Agent policy: https://meta.wikimedia.org/wiki/User-Agent_policy for url: https://upload.wikimedia.org/wikipedia/commons/1/14/Orange-Fruit-Pieces.jpg

    When I googled it, I found this post (Downloading images from wikipedia gives forbidden error due to User Agent policy) that mentioned I need to be sending some user agent.

    Is there a way for me to anonymize my email address from wikipedia or is it a requirement for me if I want to use their images from a link?

    def fetch_image_from_url(url):
    headers = {"User-Agent": AppleProject/1.0 (github link and email)"}
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    return Image.open(BytesIO(response.content))


    I'm mostly trying to figure out if there's a way around their header requirements and not have my email address stored in my github repo.

    Continue reading...

Compartilhe esta Página