python postgresql TypeError:在字符串格式化过程中并非所有参数都已转换

python postgresql TypeError:在字符串格式化过程中并非所有参数都已转换,python,postgresql,typeerror,Python,Postgresql,Typeerror,命令“插入管线列表值('0.0.0.0/0')”工作正常。但是循环不起作用。这个错误意味着什么?如何摆脱她 data = ['0.0.0.0/0'] for d in data: cursor.execute("INSERT into route_list VALUES %s", d) TypeError:并非所有在字符串格式化过程中转换的参数都使用此选项: cursor.execute("INSERT into route_list VALUES (%s

命令“插入管线列表值('0.0.0.0/0')”工作正常。但是循环不起作用。这个错误意味着什么?如何摆脱她

data = ['0.0.0.0/0']

for d in data:

  cursor.execute("INSERT into route_list VALUES %s", d)
TypeError:并非所有在字符串格式化过程中转换的参数都使用此选项:

cursor.execute("INSERT into route_list VALUES (%s)", [d])
or
cursor.execute("INSERT into route_list VALUES (%s)", (d,))
or
cursor.execute("INSERT into route_list VALUES ('{0}')".format(d))

请不要。使用中所述的参数替换。对查询值使用字符串格式是错误的。@snakecharmerb使用format()时有什么错误。与format()无关@pgyogesh使用format(或f-strings)会引发与使用%插值或字符串串联完全相同的问题:开发人员必须确保每次都正确引用变量,否则可能会引入错误或漏洞。如果所有DB-API库都是免费的,那么就没有理由这样做。