DEV Community

Discussion on: Building An E-commerce Telegram Bot Using Python and Fauna.

Collapse
 
curiouspaul1 profile image
Curious Paul

Hi, this doesn't seem like the code i wrote in the demo, for this article, however this doesn't look like the code to upload an image to cloudinary looks like. You might want to check the docs or use the one i wrote on the product_info method in handlers.py from the tutorial.

Collapse
 
alvaaz profile image
Álvaro Göede Rivera • Edited

I get the same problem when doing the demo, that's why I simplified it.

def add_media(update: Update, context: CallbackContext):
  logger.info(f"El usuario {update.effective_user['username']}, subió foto")
  quote = context.user_data["new_quote"]
  photo = context.bot.getFile(update.message.photo[-1].file_id)
  file_ = open("product_image", "wb")
  photo.download(out=file_)
  send_photo = upload("product_image", width=200, height=150, crop='thumb')
Enter fullscreen mode Exit fullscreen mode
dp.add_handler(ConversationHandler(
  entry_points = [CommandHandler("new", handlers.start)],
  states={
    handlers.QUOTE: [
      MessageHandler(
          Filters.all, handlers.add_quote
      )
    ],
    handlers.MEDIA: [
      MessageHandler(Filters.photo, handlers.add_media)
    ]
  },
  fallbacks=[CommandHandler('cancel', handlers.cancel)],
  allow_reentry=True)
)
Enter fullscreen mode Exit fullscreen mode

The console show the same error:

ValueError: not enough values to unpack (expected 2, got 1)
Enter fullscreen mode Exit fullscreen mode

I know the error is upload because when I remove it the error does not appear.

Thread Thread
 
curiouspaul1 profile image
Curious Paul

I see, do you add caption to the image when you test it though.?

Thread Thread
 
alvaaz profile image
Álvaro Göede Rivera

Could you check my code and see if there is something I am doing wrong?

github.com/alvaaz/telegram_bot

I would really appreciate it

Thread Thread
 
curiouspaul1 profile image
Curious Paul

oh great!, thanks for making this easier I'll take a look