2024-06-26 14:20:57 发布
网友
我在试着换线
self.cursor.execute("select (1) from eScraperInterfaceApp_scrapeddata where productURL = '%s' limit 1") % URL
错误
Unsupported operand type(s) for %: 'long' and 'unicode'
productURL是unicode,那么我如何替换它。。。有人能帮帮我吗
您的代码正在执行以下操作:
self.cursor.execute("SQL template") % URL
它应该是:
更改)的位置:
)
self.cursor.execute("select (1) from eScraperInterfaceApp_scrapeddata where productURL = '%s' limit 1" % URL)
实际上更正确的方法是使用查询参数(防止SQL注入):
self.cursor.execute("select (1) from eScraperInterfaceApp_scrapeddata where productURL = %s limit 1", (URL,))
您没有指定使用什么数据库(和DBAPI驱动程序),但是pep249要求DBAPI支持参数替换,因此使用它代替Python字符串格式会更好。在
cursor.execute( "select (1) from eScraperInterfaceApp_scrapeddata where productURL = %s limit 1;", (URL,))
(注意参数占位符和参数作为1元组缺少引号)。在
您的代码正在执行以下操作:
它应该是:
^{pr2}$更改
)
的位置:实际上更正确的方法是使用查询参数(防止SQL注入):
您没有指定使用什么数据库(和DBAPI驱动程序),但是pep249要求DBAPI支持参数替换,因此使用它代替Python字符串格式会更好。在
(注意参数占位符和参数作为1元组缺少引号)。在
相关问题 更多 >
编程相关推荐