简体   繁体   English

内部服务器错误:在Apache中使用带sqlite + mod_wsgi的python脚本

[英]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.

相关问题 使用mod_wsgi和apache2的服务器内部错误 - server internal error with mod_wsgi and apache2 500 内部服务器错误 mod_wsgi apache &quot;importerror: No Module named &#39;django&#39; - 500 internal server error mod_wsgi apache "importerror: No Module named 'django' Django + Apache + Mod_wsgi导致500内部服务器错误(附加日志) - Django + Apache + Mod_wsgi cuasing 500 Internal Server Error (log attached) 我可以使用mod_vhost_alias和mod_wsgi在同一个Apache服务器上运行PHP和Python吗? - Can I run PHP and Python on the same Apache server using mod_vhost_alias and mod_wsgi? Django/mod_wsgi/Apache - mod_wsgi 没有使用为它编译的 Python 版本 - “ModuleNotFoundError: No module named 'math'” - Django/mod_wsgi/Apache - mod_wsgi is not using the Python version it was compiled for - “ModuleNotFoundError: No module named 'math' ” Windows XP上的mod_wsgi [django]内部服务器错误 - Internal Server Error with mod_wsgi [django] on windows xp Hello World 使用 mod_wsgi,内部错误,错误配置 - Hello World using mod_wsgi, Internal error, misconfiguration apache服务器上的ssh连接python mod_wsgi flask - ssh connection on apache server python mod_wsgi flask 尝试在apache服务器上运行mod_wsgi时出错 - Error trying to run mod_wsgi on a apache server Redhat 中的 Apache 服务器 mod_wsgi 给出 500 错误 - Apache server mod_wsgi in Redhat gives 500 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM