从cmd调用数据库的python脚本时出错

时间:2017-12-18 23:24:48

标签: python-2.7 cmd sqlite

我是一名编程学生,我们正在研究SQL注入攻击 - 问题是我无法让数据库在我的计算机上运行。任务是模拟对SQL数据库的API调用并使用python脚本 - 我已经安装了python 2.7和sqlite 3,并且使用

从cmd运行python脚本
python count_stock.py '{"productId":1}'

(脚本在下面),我已经将python和SQLite3添加到PATH。我一直收到以下错误:

Traceback (most recent call last):
  File "count_stock.py", line 12, in <module>
    input_json = json.loads(arg)
  File "C:\Python27\lib\json\__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

我做过蠢事!! ??

Python脚本:

import sys, sqlite3, json

company_db_file = 'company_data.db'

# Connect to the DB
conn = sqlite3.connect(company_db_file)
c = conn.cursor()

# Count and print stock numbers for product id
for arg in sys.argv[1:]:

    input_json = json.loads(arg)
    c.execute("SELECT amount FROM product WHERE id = " + str(input_json['productId']))
    sys.stdout.write(str(c.fetchall())+ "\n")

conn.commit()
conn.close()

0 个答案:

没有答案