我怎样才能解决这个错误呢?[英] how can I fix the error

本文是小编为大家收集整理的关于我怎样才能解决这个错误呢?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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

这是我的代码:

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()

执行代码时,我有一个错误:

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

推荐答案

您忘记了字符串末端的报价.

另外,插入语句需要列名列表; my_argv[2]不是列名.

此外,%s不是数据库参数标记;而是使用?.

另外,getpass是一个模块;您不能称呼它.

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)

其他推荐答案

您忘记保留" 应该像

sql = "INSERT INTO info_calc (application,version,path,os,user,ip) VALUES (%s, %s, %s, %s, %s, %s)"

另外一件事,在执行查询插入时需要给出值

应该是

c.execute(sql,(my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass.getuser(), machine ))

本文地址:https://www.itbaoku.cn/post/597316.html

问题描述

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

that's my code :

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.

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

Furthermore, %s is not a database parameter marker; use ? instead.

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)

其他推荐答案

you forget to keep " it should be like

sql = "INSERT INTO info_calc (application,version,path,os,user,ip) VALUES (%s, %s, %s, %s, %s, %s)"

one more thing,while executing the query insert you need to give values

it should be

c.execute(sql,(my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass.getuser(), machine ))