gpt4 book ai didi

python - % : 'long' and 'unicode' 不支持的操作数类型

转载 作者:行者123 更新时间:2023-11-28 20:47:51 25 4
gpt4 key购买 nike

我正在尝试进行字符串替换

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("SQL template" % URL)

改变)的位置:

self.cursor.execute("select (1) from eScraperInterfaceApp_scrapeddata where productURL = '%s' limit 1" % URL)

实际上更正确的方法是使用查询参数(以防止 SQL 注入(inject)):

self.cursor.execute("select (1) from eScraperInterfaceApp_scrapeddata where productURL = %s limit 1", (URL,))

关于python - % : 'long' and 'unicode' 不支持的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18012974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com