Windows Eight
Windows Eight

Reputation: 41

PyTeleBot does not send images to users after the first user

This is my code:

def paid(first, last, uid, contribution, position, number, description, img): 
    for admin in const.admins:
        sleep(10)
        bot.send_photo(admin, img)
        sleep(1)
        bot.send_message(admin, '✅Пользователь {0} {1} ID {2} оплатил заказ "рулетка".' 
                                '\nВзнос: {3} руб.'
                                '\nТовар {4} № {5} удален из резерва.'
                                '\n{6}'.format(first,
                                               last,
                                               uid,
                                               contribution,
                                               position,
                                               number,
                                               description))

According to the idea, the code should send to each admin a photo of img, but it sends it only to the first admin, for the others it gives an error:

telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: file must be non-empty"}'] " 2017-10-05 13:09:18,537 (init.py:292 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: file must be non-empty"}']

Moreover, the variable img continues to be <_io.BufferedReader name='img.jpg'>

  1. Why the code does not want to send img to the second admin?
  2. How to send an image to the second admin?

Upvotes: 3

Views: 469

Answers (1)

Ratto
Ratto

Reputation: 24

I'm assuming you want the for loop to traverse all the different images? in that case your gonna need to define it more than once

you see what you did here means that all the loops access all of the information given here again and again, with no change. the for loop does not automatically update these variables for you once you've created them using this command below:

def paid(first, last, uid, contribution, position, number, description, img): 

Upvotes: 0

Related Questions