【问题标题】:Python SQL Injection safePython SQL 注入安全
【发布时间】:2018-10-14 01:58:32
【问题描述】:

简短的问题:我想让我的代码更安全,但在这一行中它崩溃了:

self.cursor.execute("SELECT device_name FROM device WHERE device_id = %s", self.device_id)

这工作正常,但对于注入攻击不安全:

self.cursor.execute("SELECT device_name FROM device WHERE device_id = " + str(self.device_id))

我不知道,第一行有什么问题。

[...] raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): Unknown error

【问题讨论】:

标签: python sql python-2.7


【解决方案1】:

第二个参数必须是参数的集合(元组、列表或字典)。

self.cursor.execute("SELECT device_name FROM device WHERE device_id = %s", 
                    (self.device_id,))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-12
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多