S
S
SHADRIN2019-02-04 09:28:48
Python
SHADRIN, 2019-02-04 09:28:48

Python how to run loop multithreaded QIWI API? and how to implement loop restart?

The bottom line is that there is a telegram bot, I want to implement payment verification.
1 The bot issues an invoice
2 And starts the verification cycle
3 If a person has paid, then all the rules are normal, nothing is wrong
4 If the payment is canceled, the cycle stops (I thought for a long time how to do it xD)
But after someone, it doesn’t matter who canceled the cycle, any user, then the bot just stops issuing a new account, gives an error "OverridingEx", I began to catch it so that it would not crash, but the essence of the problem remained.
Who can tell how to solve the problem.
I use SimpleQIWI
The cycle itself:
PS I commented on everything I could

try:
                    price = 1 #Цена товара
                    comment = api.bill(price) #Генерирует комментарий платежа и тут сообственна ошибка
                    keyboard = types.InlineKeyboardMarkup() #Клавиатура
                    keyboard.add(*[types.InlineKeyboardButton(text='Отмена', callback_data='Отмена_TEST')])  #Клавиатура
                    bot.send_message(x.message.chat.id, 'Вам выставлен счет:\n'
                                                      'Сумма к оплате: 1 RUB\n'
                                                      'QIWI кошелек: ' +str(qphone)+'\n'
                                                      'Комментарий платежа: \n<b>'+str(comment)+'</b>',reply_markup=keyboard, parse_mode="Html")
                    api.start() #Запускает проверку
                    coklend__asd = 2 #Переменная для отмены цикла
                    a = 1 #Переменная для цикла
                    while a <= 5: #Ну поняли
                        if api.check(comment): #Если найдет комментарий то пропустит
                            bot.send_message(x.message.chat.id, 'Платёж получен!', parse_mode="Html")
                            break
                        else:
                            time.sleep(5) #Спим
                            a += 1 #Добавляем в переменную
                            print(a) #Выводим 
                    api.stop()#Остановит проверку
            except OverridingEx: #Ловлю ошибку
                bot.send_message(x.message.chat.id, 'ERROR')

Here's the error itself:
PS don't even think about sending me the SimpleQIWI documentation to read, it is 1 project on github and says nothing about it.
C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\python.exe D:/repos/untitled/MAIN.py
2019-02-04 10:25:27,678 (util.py:65 WorkerThread2) ERROR - TeleBot: "OverridingEx occurred, args=('Overriding bill!',)
Traceback (most recent call last):
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 59, in run
    task(*args, **kwargs)
  File "D:/repos/untitled/MAIN.py", line 220, in inline
    comment = api.bill(price)
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\SimpleQIWI\Session.py", line 106, in bill
    raise OverridingEx('Overriding bill!')
SimpleQIWI.Errors.OverridingEx: Overriding bill!
"
Traceback (most recent call last):
  File "D:/repos/untitled/MAIN.py", line 346, in <module>
    bot.polling(none_stop=True)
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 389, in polling
    self.__threaded_polling(none_stop, interval, timeout)
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 413, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 108, in raise_exceptions
    six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 59, in run
    task(*args, **kwargs)
  File "D:/repos/untitled/MAIN.py", line 220, in inline
    comment = api.bill(price)
  File "C:\Users\saxar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\SimpleQIWI\Session.py", line 106, in bill
    raise OverridingEx('Overriding bill!')
SimpleQIWI.Errors.OverridingEx: Overriding bill!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2019-02-04
@Norkotik

Write a validation function that returns either ok or an error. Run it in a cycle, limiting the number of cycles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question