简体   繁体   English

Python sqlite内部服务器错误

[英]Python sqlite Internal Server Error

I'm working on a website powered by Python at the back end. 我正在后端使用Python驱动的网站上。 The following script receives values from JavaScript and should write the same to a database. 以下脚本从JavaScript接收值,并将其写入数据库。

import cgi
import sqlite3

form = cgi.FieldStorage()
brand = form['brand'].value
model = form['model'].value

db = sqlite3.connect("dbase.db")
query = "INSERT INTO requests (brand, model) VALUES (?, ?)"
db.execute(query, (brand, model,))
db.commit()
db.close()

But invoking the script returns 500 Internal Server Error . 但是调用脚本将返回500 Internal Server Error To my surprise, the following code, run independently on terminal works perfect. 令我惊讶的是,以下代码在终端上独立运行非常完美。

import sqlite3

brand = 'nokia'
model = 'lumia 625'

db = sqlite3.connect("dbase.db")
query = "INSERT INTO requests (brand, model) VALUES (?, ?)"
db.execute(query, (brand, model,))
db.commit()
db.close()

I'm using Python 2.7.5 and running on Lighttpd server. 我正在使用Python 2.7.5并在Lighttpd服务器上运行。 Also, the db.execute() portion is where the error occurs. 另外, db.execute()部分是发生错误的地方。 How can I correct the problem? 我该如何解决该问题?

This might happen for not having database dbase and table requests .You need a database and table for inserting fields.You can create database with this query 这可能会发生因没有数据库dbase和表的requests 。你需要插入fields.You可以用这个查询创建数据库的数据库和表

sqlite3 dbase.db

And next you need to create a table for this like 接下来,您需要为此创建一个表

create table requests(brand varchar(10), model varchar2(10));

Then your file will execute 然后您的文件将执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM