[Python] How to send image by URL with telegram API using python?

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code to send image, but I can send only local images, how can I send image by specifying just URL?


    from PIL import Image
    import requests

    img = open("https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1172&q=80")

    TOKEN = "token"
    CHAT_ID = "@channel_id"

    url = f'https://api.telegram.org/bot{TOKEN}/sendPhoto?chat_id={CHAT_ID}'


    print(requests.get(url, files={'photo': img}))

    How can I send image by link?

    Thank you in advance.

    Continue reading...

Compartilhe esta Página