Search code examples
pythonpython-3.xpy-telegram-bot-api

PyTelegramBotAPi can't send_invoice on python3.9


I'm working with the payment system for the first time and I can't send it, it gives this error:

    Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/m1rsadikov/tele-bot/venv/lib/python3.8/site-packages/telebot/__init__.py", line 2140, in send_invoice
    result = apihelper.send_invoice(
  File "/home/m1rsadikov/tele-bot/venv/lib/python3.8/site-packages/telebot/apihelper.py", line 1353, in send_invoice
    'prices': _convert_list_json_serializable(prices)}
  File "/home/m1rsadikov/tele-bot/venv/lib/python3.8/site-packages/telebot/apihelper.py", line 1597, in _convert_list_json_serializable
    for r in results:
TypeError: 'int' object is not iterable

And this is what I send:

    bot.send_invoice(message.from_user.id, title='Working Time Machine',
                     description='Want to visit your great-great-great-grandparents?'
                                 ' Make a fortune at the races?'
                                 ' Shake hands with Hammurabi and take a stroll in the Hanging Gardens?'
                                 ' Order our Working Time Machine today!',
                     provider_token=provider_token,
                     currency='usd',
                     photo_url='http://erkelzaar.tsudao.com/models/perrotta/TIME_MACHINE.jpg',
                     photo_height=512,  # !=0/None or picture won't be shown
                     photo_width=512,
                     photo_size=512,
                     is_flexible=False,  # True If you need to set up Shipping Fee
                     prices=100,
                     start_parameter='time-machine-example',
                     invoice_payload='HAPPY FRIDAYS COUPON')

Solution

  • It's was a mistake if u use price=100 or another u must use:

    prices = [types.LabeledPrice(label='Working Time Machine', amount=get_amount(basket))]