[英]Internal Server error: using python script with sqlite + mod_wsgi in apache
This is my code example. 这是我的代码示例。
import sqlite3
def application(environ, start_response):
output = "<p> LOG</p>"
db = sqlite3.connect('/root/example.db')
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute('''SELECT id, message,date FROM table''')
for row in cursor:
print('{0} : {1}, {2}'.format(row['id'], row['message'], row['date']))
db.close()
start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
return output
I get Internal Server Error. 我收到内部服务器错误。
How would solve the problem? 如何解决这个问题?
Since you webserver (hopefully) doesn't run as the root
-User, placing your database in the /root
directory will not work. 由于您的网络服务器(希望)没有以
root
用户身份运行,因此将数据库放置在/root
目录中将不起作用。
You habe to put the database in a directory that is writable by your webserver (as it looks to me, that would be /var/www
for you). 您必须将数据库放在Web服务器可写的目录中(在我看来,对您而言,它将是
/var/www
)。
And just to prevent further privilege problems, the database file needs to be readable and writable by the webserver as well. 并且为了防止进一步的特权问题,数据库文件也需要由Web服务器读取和写入。 On Ubuntu/Debian systems, this can be done with
在Ubuntu / Debian系统上,可以使用
chown www-data:www-data /var/www/example.db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.