如何解决错误 [英] how can I fix the error

查看:144
本文介绍了如何解决错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里是新手,我有我的代码,在我创建我的SQL查询之前运行良好。
我使用sqlite3作为数据库。

I'm novice here and I have my code, there is running good before I create my SQL query. I use sqlite3 as database.

这是我的代码

code.py

print """<INPUT  Value="Valider" Type="SUBMIT" >

<head>
   <script type="text/javascript">

   {

   alert('thank you.');

   }

   </script>
   </head>"""

print "</body>"
print "</html>"

conn = sqlite3.connect('database.sqlite')
conn.row_factory = sqlite3.Row 
c = conn.cursor()

sql = "INSERT INTO info_calc (my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass.getuser(), machine ) VALUES (%s, %s, %s, %s, %s, %s)

try:
    c.execute(sql)
    conn.commit()
except:
     conn.rollback()

cursor.close()

当我执行我的代码时,

when I execute my code, I have this error :

sql = "INSERT INTO info_calc (my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass.getuser(), machine ) VALUES (%s, %s, %s, %s, %s, %s)
                                                                                                                                               ^
SyntaxError: EOL while scanning string literal


推荐答案

您忘了字符串末尾的报价。

You forgot the quote at the end of the string.

此外,INSERT语句需要一个列名列表; my_argv [2] 不是列名。

Also, the INSERT statement wants a list of column names; my_argv[2] is not a column name.

此外,%s 不是数据库参数标记;

另外, getpass 模块;您不能调用它。

Additionally, getpass is a module; you cannot call it.

sql = "INSERT INTO info_calc (application,version,path,os,user,ip) "+
      "VALUES (?,?,?,?,?,?)"
args = my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass.getuser(), machine
c.execute(sql, args)

这篇关于如何解决错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆