linux web访问sqlite,【linux】flask部署到linux上无法访问sqlite3数据库

自己笔记本上(Windows 10)测试可以正常运行

部署到服务器上失败

报错信息

i Feb 09 20:42:22.808818 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] mod_wsgi (pid=2365): Exception occurred processing WSGI script ‘/data/wwwroot/default/OBlog/flask.wsgi’. [Fri

Feb 09 20:42:22.808861 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] Traceback (most recent call last): [Fri Feb 09 20:42:22.809462 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/usr/lib64/python3.4/site-packages/flask/app.py”, line 1997, in

call [Fri Feb 09 20:42:22.809472 2018] [wsgi:error] [pid 2365] [client 223.91.36.119:26414] return self.wsgi_app(environ,

start_response) [Fri Feb 09 20:42:22.809502 2018] [wsgi:error] [pid

2365] [client 223.91.36.119:26414] File

“/usr/lib64/python3.4/site-packages/flask/app.py”, line 1985, in

wsgi_app [Fri Feb 09 20:42:22.809507 2018] [wsgi:error] [pid 2365]

[client 223.91.36.119:26414] response = self.handle_exception(e)

[Fri Feb 09 20:42:22.809527 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/usr/lib64/python3.4/site-packages/flask/app.py”, line 1540, in

handle_exception [Fri Feb 09 20:42:22.809531 2018] [wsgi:error] [pid

2365] [client 223.91.36.119:26414] reraise(exc_type, exc_value,

tb) [Fri Feb 09 20:42:22.809640 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/usr/lib64/python3.4/site-packages/flask/_compat.py”, line 33, in

reraise [Fri Feb 09 20:42:22.809647 2018] [wsgi:error] [pid 2365]

[client 223.91.36.119:26414] raise value [Fri Feb 09

20:42:22.809671 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/usr/lib64/python3.4/site-packages/flask/app.py”, line 1982, in

wsgi_app [Fri Feb 09 20:42:22.809675 2018] [wsgi:error] [pid 2365]

[client 223.91.36.119:26414] response =

self.full_dispatch_request() [Fri Feb 09 20:42:22.809693 2018]

[wsgi:error] [pid 2365] [client 223.91.36.119:26414] File

“/usr/lib64/python3.4/site-packages/flask/app.py”, line 1614, in

full_dispatch_request [Fri Feb 09 20:42:22.809697 2018] [wsgi:error]

[pid 2365] [client 223.91.36.119:26414] rv =

self.handle_user_exception(e) [Fri Feb 09 20:42:22.809713 2018]

[wsgi:error] [pid 2365] [client 223.91.36.119:26414] File

“/usr/lib64/python3.4/site-packages/flask/app.py”, line 1517, in

handle_user_exception [Fri Feb 09 20:42:22.809717 2018] [wsgi:error]

[pid 2365] [client 223.91.36.119:26414] reraise(exc_type,

exc_value, tb) [Fri Feb 09 20:42:22.809733 2018] [wsgi:error] [pid

2365] [client 223.91.36.119:26414] File

“/usr/lib64/python3.4/site-packages/flask/_compat.py”, line 33, in

reraise [Fri Feb 09 20:42:22.809736 2018] [wsgi:error] [pid 2365]

[client 223.91.36.119:26414] raise value [Fri Feb 09

20:42:22.809752 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/usr/lib64/python3.4/site-packages/flask/app.py”, line 1610, in

full_dispatch_request [Fri Feb 09 20:42:22.809755 2018] [wsgi:error]

[pid 2365] [client 223.91.36.119:26414] rv =

self.preprocess_request() [Fri Feb 09 20:42:22.809771 2018]

[wsgi:error] [pid 2365] [client 223.91.36.119:26414] File

“/usr/lib64/python3.4/site-packages/flask/app.py”, line 1831, in

preprocess_request [Fri Feb 09 20:42:22.809774 2018] [wsgi:error] [pid

2365] [client 223.91.36.119:26414] rv = func() [Fri Feb 09

20:42:22.809885 2018] [wsgi:error] [pid 2365] [client

223.91.36.119:26414] File “/data/wwwroot/default/OBlog/OBlog/views/default.py”, line 76, in

before_request [Fri Feb 09 20:42:22.809892 2018] [wsgi:error] [pid

2365] [client 223.91.36.119:26414] g.db =

sqlite3.connect(app.config[‘DATABASE’]) [Fri Feb 09 20:42:22.809914

2018] [wsgi:error] [pid 2365] [client 223.91.36.119:26414]

sqlite3.OperationalError: unable to open database file

看了下,大概是sqlite3.OperationalError: unable to open database file访问数据库失败

但是我数据库和文件夹都给了777权限

a68015c0a86ee79a2bc4192d0c87d2c9.png

实在不知道为什么会这样(我直接ssh里运行python然后import sqlite3 能正常读取数据库)

回答

把数据库换成绝对路径可以了

虽然相对路径没错,但是必须是绝对路径才行

不是很清楚你创建app和config中的代码怎么写的,但是应该不是相对路径的问题。

我使用相对路径就可以的。

建议下次提问的时候把报错信息、相关代码全贴出来。

# config文件配置

SQLALCHEMY_DATABASE_URI = 'sqlite+pysqlite:///./test.db'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值