无法处理参数:str() 它必须是列表、元组或字典类型
P粉585541766
P粉585541766 2024-01-02 09:02:53
0
1
513

这不起作用,并显示错误“无法处理参数:str(在 Ponteland 提供优质轮胎服务),它必须是列表、元组或字典类型”

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)

但是,当直接在查询中传递值时,它似乎运行时没有任何错误。

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)

尝试通过变量传递字符串参数,但似乎不起作用。

稍后找到答案

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

全部回复(1)
P粉447495069

如错误所述:

您的参数必须是预期类型之一,但您正在发送 str

您在 val 变量上添加了括号:

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

但是元组是由逗号,而不是括号定义的,这应该有效:

val = ("Providing Quality Tyre Services in Ponteland",)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板