У меня есть вот такой код
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, 'Hey Start')
@bot.message_handler(commands=['info'])
def send_welcome(message):
info = ('Hey Info')
bot.reply_to(message, info)
import uuid
@bot.message_handler(content_types=["photo"])
def answer_photo(message):
photo = bot.get_file(message.photo[-1].file_id)
# URL direction to image
photo_url = "https://api.telegram.org/file/bot{0}/{1}".format(
TOKEN, photo.file_path)
# Computer Vision parameters
r = requests.get(photo_url)
file_name = str(uuid.uuid4()) + '.png'
if r.status_code == 200:
with open('temp/' + file_name, 'wb') as f:
f.write(r.content)
else:
bot.reply_to(message, 'something fails... 1')
return
img = open('temp/' + file_name, 'rb')
#img = open('inpred.png', 'rb')
payload = {"image":img}
bot.send_chat_action(message.chat.id, 'typing')
try:
r = requests.post(KERAS_REST_API_URL, files=payload).json()
except:
bot.reply_to(message, 'something fails.... 2')
print(r)
time.sleep(1)
img_path = None
print()
try:
if r['success']:
img_path = r['result_path']
img_result = open(img_path, 'rb')
bot.reply_to(message, photo_url)
bot.send_photo(message.chat.id, img_result, reply_to_message_id=message.message_id)
img_path = r['mask_path']
img_result = open(img_path, 'rb')
bot.reply_to(message, photo_url)
bot.send_photo(message.chat.id, img_result, reply_to_message_id=message.message_id)
img_path = r['cg_path']
img_result = open(img_path, 'rb')
bot.reply_to(message, photo_url)
bot.send_photo(message.chat.id, img_result, reply_to_message_id=message.message_id)
else:
bot.reply_to(message, 'something fails... 3 ')
except:
bot.reply_to(message, 'something fails... 4')
@bot.message_handler(func=lambda m: True)
def reply_all(message):
if message.chat.type == "private":
bot.reply_to(message, 'Please send me an image so I can describe it!')
if not os.path.exists('temp'):
os.makedirs('temp')
bot.polling(none_stop=True)
while True:
time.sleep(5)
Но строка с
r = requests.post(KERAS_REST_API_URL, files=payload).json()
выдает ошибку
2020-02-27 15:41:14,292 (util.py:66 WorkerThread1) ERROR - TeleBot: "JSONDecodeError occurred, args=('Expecting value: line 1 column 1 (char 0)',)
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\telebot\util.py", line 60, in run
task(*args, **kwargs)
File "C:\Users\user\Desktop\bot\bot\tbot.py", line 55, in answer_photo
r = requests.post(KERAS_REST_API_URL, files=payload).json()
File "C:\Python37\lib\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python37\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
"
Traceback (most recent call last):
File "C:\Users\user\Desktop\bot\bot\tbot.py", line 92, in
bot.polling(none_stop=True)
File "C:\Python37\lib\site-packages\telebot\__init__.py", line 392, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Python37\lib\site-packages\telebot\__init__.py", line 416, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Python37\lib\site-packages\telebot\util.py", line 109, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Python37\lib\site-packages\six.py", line 703, in reraise
raise value
File "C:\Python37\lib\site-packages\telebot\util.py", line 60, in run
task(*args, **kwargs)
File "C:\Users\user\Desktop\bot\bot\tbot.py", line 55, in answer_photo
r = requests.post(KERAS_REST_API_URL, files=payload).json()
File "C:\Python37\lib\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python37\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Есть ли способ это исправить?