python - psycopg2.errors.SyntaxError:“C”或附近的语法错误
问题描述
hwid1 = str(subprocess.check_output(
'wmic csproduct get uuid')).split('\\r\\n')[1].strip('\\r').strip() # Get Hard Ware Id of the pc
def AutoUpdateDB():
SQL.execute(f"select hwid from Accounts WHERE hwid = {hwid1}")
result_user = SQL.fetchone()
print(result_user[0])
time.sleep(5555)
我正在尝试这段代码,它给了我错误
我试图解决这个问题,但它仍然无法正常工作
这是错误
psycopg2.errors.SyntaxError: "C"
LINE 1 处或附近的语法错误: ...ect * from Accounts WHERE hwid = AD902276-A4F9-961C-492B-2CF ...
<br/>^
解决方案
其他人已经指出了为什么你会得到你得到的特定错误,但我想提一下,解决它的方法几乎总是使用参数化查询,即类似
SQL.execute("SELECT hwid FROM Accounts WHERE hwid = %s", [hwid1])
如果 hwid1 包含“有趣”字符,这可以为您省去很多麻烦。
推荐阅读
- c# - 我无法在 SQL Server 上将 Devart 与 Entity Framework Core 一起使用
- jmeter - 即使在通过 JMeter 启动应用程序时页面内容未加载,是否可以运行导入的脚本?
- ruby-on-rails - Ruby on rails 将行提取到 pdf 并转换
- asp.net - Blazor webassembly pwa 会话存储在部署到 Azure 后不持久
- css - 根据 Spartacus 中的页面槽更改 PageTemplate 样式
- c - 如果它是字符串,如何在主函数中修改/使用命令行参数?
- twig - 使用 jQuery 将变量移动到另一个 html 并加载它
- python - 如何根据给定的字典制作熊猫数据框的集群?
- r - 在 glmmTMB R 包中指定截断点
- reactjs - 为什么刷新页面后状态清除?