X
X
Xpym4uk762020-10-02 16:21:01
Python
Xpym4uk76, 2020-10-02 16:21:01

How to fix JSON (python + qiwi api) error?

The databases are created, they work fine, but when I enter a phone number, I get this error:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0 )


import telebot
import requests
import json

def process_qiwi_number_step(message):
  connection = sqlite3.connect('database.db')
  cursor = connection.cursor()
  connection2 = sqlite3.connect('payments_sql.db')
  cursor2 = connection2.cursor()
  
  phone_num = message.text
  sum = 1
  random_code = random.randint(100000, 999999)
  
  cursor2.execute("CREATE TABLE IF NOT EXISTS payment_query(user_id INTEGER, phone TEXT, sum INTEGER, code INTEGER)")
  
  cursor2.execute(f"INSERT INTO payment_query VALUES({message.from_user.id}, {phone_num}, {sum}, {random_code})")
  
  cursor.execute(f'SELECT balance_rub FROM USERS WHERE user_id = {message.from_user.id};')
  balancerub = cursor.fetchone()[0]
  cursor.execute(f'SELECT user_id FROM USERS WHERE user_id = {message.from_user.id};')
  myid = cursor.fetchone()[0]
  markup = types.ReplyKeyboardMarkup(row_width=3, resize_keyboard=True)
  input_1 = types.KeyboardButton("Играть")
  input_2 = types.KeyboardButton("️Кабинет")
  input_3 = types.KeyboardButton("Помощь")
  input_4 = types.KeyboardButton("Контакты")
  markup.add(input_1)
  markup.add(input_2, input_3)
  markup.add(input_4)

  QIWI_TOKEN = 'Токен тут стоит'
  QIWI_ACCOUNT = '+Тут мой номер'

  s = requests.Session()
  s.headers['authorization'] = 'Bearer ' + QIWI_TOKEN  
  parameters = {'rows': '50'}
  h = s.get('https://edge.qiwi.com/payment-history/v1/persons/'+ QIWI_ACCOUNT +'/payments', params = parameters)
  req = json.loads(h.text)
  result = cursor2.execute(f"SELECT * FROM payment_query WHERE user_id = {message.from_user.id}").fetchone()
  phone_get = result[1] 
  random_code_get = result[3]
  sum_get = result[2]
  
  print(req)

  try:
    for i in range(len(req['data'])):
      if req['data'][i]['account'] == phone_get:
        if req['data'][i]['comment'] == random_code_get:
          if req['data'][i]['sum']['amount'] == sum_get:
            cursor2.execute(f"DELETE FROM payment_query WHERE user_id = {message.from_user.id}")
            bot.send_message(message.chat.id, '⚠OKEY', parse_mode='html')
      else:
        cursor2.execute(f"DELETE FROM payment_query WHERE user_id = {message.from_user.id}")
  except Exception as err:
    raise(err)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-10-02
@Xpym4uk76

h.text contains None.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question