0

I'm working on a function in python that reads values from MySql. When I insert using the same format there are no errors but when I select it gives me the error mysql.connector.errors.ProgrammingError: Could not process parameters: str(555), it must be of type list, tuple or dict Here is my code that is giving the error

cursor.execute('SELECT * FROM LIBS')
            result = cursor.fetchall()
            for row in result:
                user_id = row[0]
                song_id = row[1]
                if(user_id == userno):
                    cursor.execute("SELECT s_title FROM SONG WHERE s_id = (%s)", (song_id))
                    print(row[1])

What I don't understand is when I use the exact same format for INSERT with (%s) there are no errors

I tried adding a comma inside the song_id and then running them as cursor.execute("SELECT s_title FROM SONG WHERE s_id = (%s)", (song_id,)) but I got the error mysql.connector.errors.InternalError: Unread result found.

1
  • I added a second duplicate link to explain the "Unread result found" error message. Commented Dec 12, 2022 at 17:05

1 Answer 1

0

params must be a list, tuple or dict (see docs)

cursor.execute("SELECT s_title FROM SONG WHERE s_id = (%s)", (song_id,))

Note the comma after song_id. Without the comma, it's just a str and not a tuple. This is only necessary for creating tuples with one element.

Sign up to request clarification or add additional context in comments.

2 Comments

Doing it like that gives me error unread result found
Yeah, that's because you are not using the cursor properly. You are executing a statement, but do not consume the result before executing another statement. You can set buffered=True when creating the cursor.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.