Hello everyone I am writing a telegram bot that downloads files sent by the user, but I get this exception:404, message=’Not Found. I’ve been racking my brain for a long time about what, I’ve searched the entire Internet, but I haven’t found anything. I write in python using the aoigram3 library, the code works on my PC, but the remote local server throws this exception, I will be glad of your help, thanks for earlier.
TOKEN=""
session = AiohttpSession(api = TelegramAPIServer.from_base('http://localhost:8081'))
bot = Bot(TOKEN,session=session)
dp = Dispatcher()
a= logging.basicConfig(level=logging.INFO)
save_path_apk = None
file_info = None
class Form_apk(StatesGroup):
opisanie = State()
apk = State()
photo = State()
class Form_post(StatesGroup):
photo = State()
opisanie = State()
async def the_re_assembly_APK(message:Message,files,thumbnail,caption):
try:
await bot.send_document(document=files, chat_id=-1001161287029, thumbnail=thumbnail,
caption=caption)
directory_image = glob.glob(r'/root/hosting_bot/DATA/IMAGE*')
directory_apk = glob.glob(r'/root/hosting_bot/DATA/APK*')
for f in directory_image:
os.remove(f)
for f in directory_apk:
os.remove(f)
except:
await message.answer(text="Ошибка")
d_i = r'/root/hosting_bot/DATA/IMAGE*'
d_apk = r'/root/hosting_bot/DATA/APK*'
if os.path.isdir(d_apk):
if not os.listdir(d_apk):
await message.answer(text="Загрузите ваш файл с расширением .apk")
if os.path.isdir(d_i):
if not os.listdir(d_i):
await message.answer(text="Загрузите ваше изображение")
@dp.message(Command("start"))
async def command_start_hendler(message: Message):
kb = [[KeyboardButton(text="APK Constructor⚙️"),KeyboardButton(text="Post Constructor????")]]
keyboard = ReplyKeyboardMarkup(keyboard=kb, resize_keyboard=True)
await message.answer(f"Здравствуйте {message.from_user.full_name}",reply_markup=keyboard)
@dp.message(lambda message: message.text == "APK Constructor⚙️")
async def apk_file_setting(message:Message,state:FSMContext):
await state.set_state(Form_apk.opisanie)
await message.answer("Отправьте описание файла ????:")
@dp.message(Form_apk.opisanie)
async def form_opisanie(message:Message,state:FSMContext):
await state.update_data(opisanie=message.text)
await state.set_state(Form_apk.apk)
await message.answer("Отправьте файл с расширением .apk????")
@dp.message(Form_apk.apk, F.document)
async def form_apk(message:Message,state:FSMContext):
try:
f = message.document.file_name
basename, extension = os.path.splitext(f)
if extension == ".apk":
#PROBLEM CODE
down = await message.answer(text="Скачивается ⬇️")
await message.answer(text="1")
global file_info
file_info = await bot.get_file(message.document.file_id)
await message.answer(text="2")
global save_path_apk
save_path_apk = rf'/root/hosting_bot/APK'
#asa = 'https://api.telegram.org/file/bot<token>/<file_path> to get the file.'
##time.sleep(10)
downlaod_apk=await bot.download_file(file_path=file_info.file_path,destination=save_path_apk)
await message.answer(text="4")
global file_name_apk
file_name_apk = os.path.join(save_path_apk,f'{message.document.file_name}')
await message.answer(text="5")
with open('/root/hosting_bot/APK'+file_name_apk,"wb") as new_file:
await message.answer(text="6")
new_file.write(downlaod_apk.read())
await message.answer(text="7")
await bot.delete_message(chat_id=message.chat.id, message_id=down.message_id)
await message.answer(text="8")
global files
await message.answer(text="9")
# files = FSInputFile(file_name_apk)
# await message.answer(text="10")
await message.answer("Скачано ✔️")
# await state.update_data(apk=files)
# await state.set_state(Form_apk.photo)
# await message.answer("Отправьте изображение ????️")
#PROBLEM CODE
else:
await message.answer(text="Ошибка❗ Отправьте файл с расширением .apk????")
except aiohttp.client_exceptions.ClientResponseError as e:
await message.answer(text=f"{e}")
#await message.answer(f"URL запроса: {file_info.file_path}")
@dp.message(Form_apk.photo, F.photo)
async def form_photo(message:Message,state:FSMContext):
photo_id = message.photo[-1]
file_info = await bot.get_file(photo_id.file_id)
global save_path
save_path = r'/root/hosting_bot/DATA/IMAGE'
download_photo = await bot.download_file(file_info.file_path)
global file_name
file_name = os.path.join(save_path, f'photo_{photo_id.file_id}.jpg')
global new_file
with open(file_name, "wb") as new_file:
new_file.write(download_photo.read())
global thumbnail
thumbnail = FSInputFile(file_name)
await message.answer("Скачано ✔️")
await state.update_data(photo=thumbnail)
data = await state.get_data()
await the_re_assembly_APK(message,data["apk"],data["photo"],data["opisanie"])
await message.answer("Apk отправлен в канал ✔️")
await state.clear()
@dp.message(Form_apk.photo, ~F.photo)
async def form_photo(message:Message):
await message.answer("Отправьте изображание ????️")
@dp.message(lambda message: message.text == "Post Constructor????")
async def apk_file_setting(message:Message,state:FSMContext):
await state.set_state(Form_post.photo)
await message.answer(text="Отправьте изображение ????️")
@dp.message(Form_post.photo,F.photo)
async def form_photo_post(message:Message,state:FSMContext):
photo_id = message.photo[-1]
await state.update_data(photo=photo_id.file_id)
await state.set_state(Form_post.opisanie)
await message.answer(text="Отправьте описание ????:")
@dp.message(Form_post.photo,~F.photo)
async def form_photo_post(message:Message,state:FSMContext):
await message.answer(text="Ошибка❗ Вы отправили не изображение ❌")
await message.answer(text="Отправьте изображение ????️")
@dp.message(Form_post.opisanie,F.text)
async def form_photo_post(message:Message,state:FSMContext):
await state.update_data(opisanie=message.text)
#global data
data = await state.get_data()
await bot.send_photo(chat_id=-1001161287029,photo=data["photo"],caption=data["opisanie"])
#await bot.send_photo(chat_id=,photo=data["photo"],caption=data["opisanie"])
await message.answer(text="Пост отправлен в канал ✔️")
await state.clear()
@dp.message(Form_post.opisanie, ~F.text)
async def form_photo_post(message: Message, state: FSMContext):
await message.answer(text="Ошибка❗ Вы отправили не текст")
async def main():
try:
await dp.start_polling(bot)
except TelegramAPIError as e:
if isinstance(e,asyncio.TimeoutError):
print(e)
asyncio.run(main())
ProgrammerBandit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.