"The provided media object is invalid.." как забрать с сайта картинку по ссылке?

Рейтинг: 0Ответов: 1Опубликовано: 16.03.2023

Хочу забрать с сайта картинку по ссылке: img = 'https://nnmstatic.win/forum/image.php?link=%2F%2Fi5.imageban.ru%2Fout%2F2023%2F03%2F09%2F83c53cc82c4d4336aa3cb220142e868b.jpg'

Выдаёт ошибку:

MediaEmptyError: The provided media object is invalid or the current account may not be able to send it (such as games as users) (caused by SendMediaRequest)

С другого сайта забираю без проблем по ссылке: img = 'https://otdel566.ru/visualData/images/main.jpg'

Подскажите пожалуйста как решить этот вопрос?

Часть кода где использую:

    async def greeting():
    global posted_q
    response = requests.get("https://nnmclub.to/forum/portal.php?c=10")
    soup = BS(response.text, 'html.parser')
    news = soup.find_all("table", class_="pline")
    array_news = []
    for n in news:
      h2 = n.find("a", class_="pgenmed")
      img = n.find("var", class_="portalImg")
      description = n.find("span", class_="portbody")
      if description != None:
        # img = 'https://otdel566.ru/visualData/images/main.jpg'
        img = 'https://nnmstatic.win/forum/image.php?link=%2F%2Fi5.imageban.ru%2Fout%2F2023%2F03%2F09%2F83c53cc82c4d4336aa3cb220142e868b.jpg'
        h2 = h2.get("title")
        if h2 not in posted_q:
          massage = f'**{h2}**\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n{description.text}'
          await main(massage, img)
          posted_q.appendleft(h2)

async def main(massage, img):
    async with TelegramClient(session_name, api_id, api_hash) as client:
       await client.send_file('me', img, caption=massage)

await greeting()

Ответы

▲ 0

Решил вопрос копирование изображения на диск с последующей отправкой.

if description != None:
    image = img.get("title") # Вытаскиваем ссылки на картинки
    h2 = h2.get("title") # Вытаскиваем названия фильмов
    if h2 not in posted_q:
      massage = f'**{h2}**\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n{description.text}' # Оформляем описание
      response = requests.get(image)# Загружаем файл картинки
      with open('image.jpg', 'wb') as f: # Сохраняем картинку на диск
        f.write(response.content)
      img = 'image.jpg'
      await main(massage, img)