我正在尝试遵循本教程:
我被困在这里:当我在lighttpd下运行时,我收到了这个错误:
<class 'sqlalchemy.exc.OperationalError'>: (OperationalError) unable to open database file u'UPDATE user SET last_seen=? WHERE user.id = ?' ('2014-08-03 14:51:51.681210', 2)
args = ('(OperationalError) unable to open database file',)
我尝试的事情:
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + '/home/pi/microblog/app.db? check_same_thread=False'
不,仍然会收到错误
我在这一点上非常好。
哦,是的,这是我的lighttpd配置文件的相关部分:
fastcgi.server = ("/microblog" =>
((
"socket" => "/tmp/microblog-fcgi.sock",
"bin-path" => "/home/pi/microblog/runp-sqlite.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
alias.url = (
"/microblog/static/" => "/home/pi/microblog/app/static/",
)
这是来自lighttpd日志的追溯:
2014-08-03 11:53:09: (response.c.544) Path : /var/www/microblog
2014-08-03 11:53:09: (mod_fastcgi.c.3035) got proc: pid: 3419 socket: unix:/tmp/microblog-fcgi.sock-0 load: 1
2014-08-03 11:53:37: (mod_fastcgi.c.2676) FastCGI-stderr: Traceback (most recent call last):
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 558, in run
protocolStatus, appStatus = self.server.handler(self)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 1118, in handler
result = self.application(environ, start_response)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request
rv = self.preprocess_request()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request
rv = func()
File "/home/pi/microblog/app/views.py", line 48, in before_request
db.session.commit()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 114, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 703, in commit
self.transaction.commit()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 361, in commit
self._prepare_impl()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 340, in _prepare_impl
self.session.flush()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1718, in flush
self._flush(objects)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1789, in _flush
flush_context.execute()
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 331, in execute
rec.execute(self)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 475, in execute
uow
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 59, in save_obj
mapper, table, update)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 485, in _emit_update_statements
execute(statement, params)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1449, in execute
params)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1584, in _execute_clauseelement
compiled_sql, distilled_params
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1698, in _execute_context
context)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1691, in _execute_context
context)
File "/home/pi/microblog/flask/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 331, in do_execute
cursor.execute(statement, parameters)
OperationalError: (OperationalError) unable to open database file u'UPDATE user SET last_seen=? WHERE user.id = ?' ('2014-08-03 15:53:37.591109', 2)
2014-08-03 11:53:40: (mod_fastcgi.c.1490) released proc: pid: 3419 socket: unix:/tmp/microblog-fcgi.sock-0 load: 0
并在config.py中:
.
.
.
SQLALCHEMY_RECORD_QUERIES = True
# slow database query threshold (in seconds)
DATABASE_QUERY_TIMEOUT = 0.5
WHOOSH_ENABLED=False
.
.
.
#SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') + '?check_same_thread=False'
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + '/home/pi/microblog/app.db' #?check_same_thread=False'
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')
答案 0 :(得分:0)
嗯,我是个大假人。
我没有对数据库文件的父目录进行读/写访问。