Unable to handle argument: str() it must be of type list, tuple or dictionary
P粉585541766
P粉585541766 2024-01-02 09:02:53
0
1
515

This does not work and displays the error "Cannot handle argument: str (Quality Tire Service in Ponteland), it must be of type list, tuple or dictionary"

import mysql.connector
from sentence_splitter import SentenceSplitter, split_text_into_sentences

mydb = mysql.connector.connect(
  host="00.00.00.00",
  user="user",
  password="password",
  database="database"
)


mycursor = mydb.cursor()


sql = ("""SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%"%s"%'""")
val = ("Providing Quality Tyre Services in Ponteland")
mycursor.execute(sql,val)

myresult = mycursor.fetchall()

for x in myresult:
      print(x)

However, when passing the value directly in the query, it seems to run without any errors.

import mysql.connector
from sentence_splitter import SentenceSplitter, split_text_into_sentences

mydb = mysql.connector.connect(
  host="00.00.00.00",
  user="user",
  password="password",
  database="database"
)


mycursor = mydb.cursor()


sql = ("""SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%"Providing Quality Tyre Services in Ponteland"%'""")
mycursor.execute(sql)

myresult = mycursor.fetchall()

for x in myresult:
      print(x)

Tried passing string parameters via variables, but that doesn't seem to work.

Find the answer later

mycursor = mydb.cursor()

val = "Providing Quality Tyre Services in Ponteland"
sql = ("SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%%%s%%'  " % val)

mycursor.execute(sql)

myresult = mycursor.fetchall()

P粉585541766
P粉585541766

reply all(1)
P粉447495069

As the error states:

Your parameter must be one of the expected types, but you are sending str

You added brackets on the val variable:

val = ("Providing Quality Tyre Services in Ponteland")

But the tuple is defined by commas , instead of brackets, this should work:

val = ("Providing Quality Tyre Services in Ponteland",)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template