Answer the question
In order to leave comments, you need to log in
I can't connect qiwi token to telegram bot, how to fix it?
I found a function on the Internet to connect a token, but for some reason it does not work
def change_qiwi_number(message):
try:
bot.send_message(message.from_user.id, " Введите токен QIWI API")
except requests.exceptions.ConnectionError:
bot.send_message(message.from_user.id, " Введите токен QIWI API")
bot.register_next_step_handler(message, change_qiwi_token)
global qiwi_login
qiwi_login = message.text
def change_qiwi_token(message):
try:
bot.send_message(message.from_user.id, " Проверка введённых QIWI данных...")
except requests.exceptions.ConnectionError:
bot.send_message(message.from_user.id, " Проверка введённых QIWI данных...")
time.sleep(2)
try:
request = requests.Session()
request.headers["authorization"] = "Bearer " + message.text
parameters = {"rows": '5'}
selectQiwi = request.get("https://edge.qiwi.com/payment-history/v2/persons/" + qiwi_login + "/payments", params = parameters)
if selectQiwi.status_code == 200:
with sqlite3.connect("shopBD.sqlite", detect_types = sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
cur = con.cursor()
cur.execute("SELECT * FROM qiwi")
while True:
row = cur.fetchone()
if row == None:
break
cur.execute("UPDATE qiwi SET login = ?, token = ? WHERE login = ?", (qiwi_login, message.text, row[0]))
if con:
con.close()
try:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "✅ QIWI токен был успешно изменён")
except requests.exceptions.ConnectionError:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "✅ QIWI токен был успешно изменён")
else:
try:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "❌ QIWI токен не прошёл проверку. Код ошибки: " + str(selectQiwi.status_code))
except requests.exceptions.ConnectionError:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "❌ QIWI токен не прошёл проверку. Код ошибки: " + str(selectQiwi.status_code))
except:
try:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "❌ QIWI токен не прошёл проверку.\nВведённые вами данные не верны")
except requests.exceptions.ConnectionError:
bot.delete_message(chat_id = message.chat.id, message_id = message.message_id + 1)
bot.send_message(message.from_user.id, "❌ QIWI токен не прошёл проверку.\nВведённые вами данные не верны")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question