Найти - Пользователи
Полная версия: Бот телеграмм - ошибка синтаксиса
Начало » Python для новичков » Бот телеграмм - ошибка синтаксиса
1
Lamptop
Добрый день! Цель написать бота, который отправлял бы все фото из заданной директории по команде.
При запуске в PyCharm выдает ошибку: SyntaxError: (unicode error) ‘unicodeescape’ codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Кто сталкивался пожалуйста помогите!

 import config
import telebot
import os
bot = telebot.TeleBot(config.token)
@bot.message_handler(content_types=['text'])
def handle_text(message):
    if message.text == 'фото':
        directory = 'C:\Users\Lamptop\Desktop\open'
        all_files_in_directory = os.listdir(directory)
        print(all_files_in_directory)
        for file in all_files_in_directory:
            img = open(directory + '/' + file, rb)
            bot.send_chat_action(message.from_user.id, 'upload photo')
            bot.send_photo(message.from_user.id, img)
            img.close()
ajib6ept
Попробуй путь по-другому указать

 directory = 'C:\\Users\\Lamptop\\Desktop\\open'
kazaff
Еще бы узнать на какую строчку он ругается и какая версия питона. Может быть среди файлов или имен папок есть странные символы или что похожее.
https://youtu.be/sgHbC6udIqc “Pragmatic Unicode, or, How do I stop the pain?”
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB