Open pfasciani opened 5 years ago
Hello @pfasciani
The problem is not from the telepot module. Its something with the io.BufferedReader built-in module, i don't know what happens but here is the workaround:
Open the file every time you need to send the photo instead once globally. Sample:
elif command == emoji.emojize(":watch: Orario :watch:", use_aliases=True): with open("/Users/piergiuliofasciani/Desktop/orario.jpg", 'rb') as photo: bot.sendPhoto(chat_id, photo, "Ecco qui", reply_markup=ReplyKeyboardMarkup( keyboard=[ [KeyboardButton(text="Torna al menu principale")] ] )),
Hope this will help you.
I'm creating a bot for me and my classmates and i'm struggling with this error
Traceback (most recent call last): File "build/bdist.macosx-10.13-intel/egg/telepot/__init__.py", line 1158, in collector callback(item) File "/Users/piergiuliofasciani/Documents/bot.py", line 30, in on_chat_message [KeyboardButton(text="Torna al menu principale")] File "build/bdist.macosx-10.13-intel/egg/telepot/__init__.py", line 539, in sendPhoto return self._api_request_with_file('sendPhoto', _rectify(p), 'photo', photo) File "build/bdist.macosx-10.13-intel/egg/telepot/__init__.py", line 499, in _api_request_with_file return self._api_request(method, _rectify(params), files, **kwargs) File "build/bdist.macosx-10.13-intel/egg/telepot/__init__.py", line 491, in _api_request return api.request((self._token, method, params, files), **kwargs) File "build/bdist.macosx-10.13-intel/egg/telepot/api.py", line 155, in request return _parse(r) File "build/bdist.macosx-10.13-intel/egg/telepot/api.py", line 150, in _parse raise exception.TelegramError(description, error_code, data) TelegramError: (u'Bad Request: file must be non-empty', 400, {u'error_code': 400, u'ok': False, u'description': u'Bad Request: file must be non-empty'})
This occurs only when I ask two times for the same Photo or File without restarting the bot.
Can I fix this?
Here's my code
`import telepot import io import time from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton import emoji import os
orario = (os.path.basename("/Users/piergiuliofasciani/Desktop/orario.jpg"), open("/Users/piergiuliofasciani/Desktop/orario.jpg"))
def on_chat_message(msg): content_type, chat_type, chat_id = telepot.glance(msg)
bot = telepot.Bot(token) bot.message_loop(on_chat_message) print("Awaiting Input...") while True: time.sleep(10)`