【发布时间】:2018-06-28 17:14:04
【问题描述】:
我正在尝试将数据插入到我的 Postgres 数据库中,我能够插入一些其他数据,但不是实际数据
这是我的查询执行函数中的数据生成器和数据发送器( (Python-Falsk)
def runid():
cmdStr = 'cd /root/Dart/log; ls -rt DartRunner*.log | tail -1 '
ret = execCmdLocal(cmdStr)
logName = ret[1].strip()
runId = ""
print('The DartRunner Log generated is: %s'%logName)
with open('/root/Dart/log/' + logName, "r") as fd:
for line in fd:
if 'runId' in line:
runId = line.split()[-1]
print('Run Id: %s'%runId)
break
print (runId) # output : Run Id: 180628-22
post_runid(runId) # output is given in below link
return jsonify({"run_id": runId})
这是我的数据库(postgres)执行方法: (Python)
def post_runid(run_id):
query = "insert into runid(runid) values(%s)"
cur.execute(query %run_id)
conn.commit()
【问题讨论】:
-
试试
cur.execute(query, run_id),这样可以避免sql注入。否则将您的查询更改为values('%s'),这样就不会出现格式问题!
标签: python sql postgresql