D
D
DTPlayer2020-07-08 14:26:14
Python
DTPlayer, 2020-07-08 14:26:14

Error in function, how to solve?

def check_payment(user_id):
    conn = sqlite3.connect('data.db')
    cur = conn.cursor()
    cur.execute('SELECT qiwi_token FROM config')
    QIWI_TOKEN = cur.fetchall()
    cur.execute('SELECT qiwi_number FROM config')
    QIWI_ACCOUNT = cur.fetchall()
    try:
        session = requests.Session()
        session.headers['authorization'] = 'Bearer ' + list(QIWI_TOKEN[0])[0]
        parameters = {'rows': '5'}
        h = session.get(
            'https://edge.qiwi.com/payment-history/v1/persons/{}/payments'.format(list(QIWI_ACCOUNT[0])[0]),
            params=parameters)
        req = json.loads(h.text)
        cur.execute(f'SELECT code FROM payment_query WHERE user_id = {user_id}').fetchone()
        result = cur.fetchall()
        comment = list(result[0])[0]

        for i in range(len(req['data'])):
            if comment in str(req['data'][i]['comment']):
                сur.execute(
                                f'UPDATE users SET access = "True" WHERE id = {call.message.chat.id}'
                            )
                conn.commit()

                return 1, req["data"][i]["sum"]["amount"]
    except Exception as e:
        print(e)

    return 0, 0


Mistake:
'in <string>' requires string as left operand, not int

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-07-08
@DTPlayer

I translate:
in stringrequires a string as the left operand, not a number.
Your comment is a number. You need to make the line
if comment in str(req['data'][i]['comment']):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question