Simple select query returning empty result set – mysql Python

  mysql-connector, mysql-python, python-3.x

I’m not sure where I’m going wrong. Simple select query results in empty result.
I need to generate random account number, send API request and check if the account number is populated in MySQL. I’m able to send API request and can see new row is populated in database when i run query manually from the program result.

def test_api(dcx_order_data) :
        test_api.accountId = payload[ "Payload" ][ "accountNumber" ] = 
            ''.join ( random.choices ( string.ascii_letters + string.digits, k=length ) )
        # few additional lines of code to tidy up the payload and send request
        response = ( url, request_body, headers=headers )
        assert response.status_code == 200

def test_policy_table(cursor):
    accountId = json.dumps(test_api.accountId)
    print("print json dump", accountId)
    print ( "***** Checking customer account: {} *****".format (accountId) )
    sql = (""" SELECT * FROM Policy where accountId IN ({}) """. format(accountId))
    print("print results", cursor.fetchall())

Output is
.print json dump "qs45HELa"
***** Checking customer account: "qs45HELa" *****
 SELECT * FROM Policy where accountId IN ("qs45HELa") 
 print results []

Code works fine if i give value in where clause in place of account number. When i run SELECT * FROM Policy where accountId IN ("qs45HELa") manually in Mysql i can see data.

Can anyone please point me in right direction.

Source: Python-3x Questions