eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.12k stars 2.03k forks source link

Get photos json parsing issue #309

Closed zkid18 closed 7 years ago

zkid18 commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? 2.3.1

  2. What OS are you using? Ubuntu 16.04.2

  3. What version of python are you using? 2.7

When I'm trying to get photo from user and work with it further, I receive such error.

obj = cls.check_json(json_type)
File "/usr/local/lib/python2.7/dist-packages/telebot/types.py", line 77, in check_json
return json.loads(json_type)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

my methods:

#main.py
@bot.message_handler(content_types= ["photo"])
def verifyUser(message):
    print ("Got photo")
    percent = userFace.verify(message.photo, config.photoToCompare)
    bot.send_message(message.chat.id, "Percentage: " + str(percent))

def polling(json_string):
    updates = telebot.types.Update.de_json(json_string)
    bot.process_new_updates([updates])

#server.py
app = Flask(__name__)

@app.route("/", methods=["POST", "GET"])
def hello():
    json_string = request.get_data()
    polling(json_string)
    print("....")
    print(request.data)
    return 'test is runing'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
Andy-ch commented 7 years ago

Hello there :)

http://stackoverflow.com/questions/42796300/get-photo-in-telegram-bot-through-pytelegrambotapi?noredirect=1#comment72708326_42796300

I think this is not the library issue but you code's issue. See my comments at SO.

Suggest closing this issue.