Не отправлять PDF-файл в боте Telegram ⇐ Python

Программы на Python
Anonymous
Не отправлять PDF-файл в боте Telegram

Сообщение Anonymous »

Я пытался отправить pdf-файл боту, но он выдает следующую ошибку: aiogram.Exceptions.TelegramBadRequest: сервер Telegram сообщает: неверный запрос: не удалось получить содержимое URL-адреса HTTP

Код: Выделить всё

import os
import uuid
import asyncio
from aiogram import Router, F, Bot
from aiogram.filters import CommandStart
from aiogram.types import Message
from gradio_client import Client, handle_file
import requests
start_router = Router()

def question_processing(fileName):
client = Client("Qwen/Qwen2-Math-Demo")
result = client.predict(
image=handle_file(fileName),
sketchpad={
"background": handle_file(
'https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
"layers": [],
"composite": None
},
question="реши, ответ в формате LaTex",
api_name="/math_chat_bot"
)
return result

@start_router.message(CommandStart())
async def cmd_start(message: Message):
await message.answer("Хай!!!")

@start_router.message(F.photo)
async def send_photo(message: Message, bot: Bot):
# Generate a unique file name for the downloaded image
local_filename = f"{uuid.uuid4()}.png"

# Get the file from the file_id and download it locally
file_info = await bot.get_file(message.photo[-1].file_id)
await bot.download_file(file_info.file_path, destination=local_filename)

await message.answer("Ваш запрос обрабатывается...")

# Run the blocking function in a separate thread
result = await asyncio.to_thread(question_processing, local_filename)
file_name = f"{uuid.uuid4()}.tex"
f = open(file_name, "w")
f.write(f"{result}")
f.close()
os.system('bash script.sh')
await message.answer_document("file.pdf")
os.remove(local_filename)
os.remove(file_name)
os.remove("file.tex")

я пробую функцию message.answer_document("name_file"), но не работает

Подробнее здесь: https://stackoverflow.com/questions/790 ... legram-bot

Вернуться в «Python»