我正在运行另一个不便寻求帮助的人的程序。该程序是一个网站。服务器端由python和flask(模块, http: //flask.pocoo.org/)编写。该程序已在服务器上成功运行。我需要做的是在上面修改一些东西。由于生产服务器不允许测试,所以我通过flask在本地开发服务器进行了测试。但是,我什至无法运行原始程序。以下来自python。
(venv)kevin@ubuntu:~/python/public_html$ python index.wsgi
Traceback(最近一次调用最后一次):文件“index.wsgi”,第 6 行,从应用程序导入应用程序作为应用程序
File "/home/kevin/python/public_html/app.py", line 27, in <module>
app = create_app()
File "/home/kevin/python/public_html/app.py", line 12, in create_app
database.init_db()
File "/home/kevin/python/public_html/database.py", line 24, in init_db
Base.metadata.create_all(engine)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/schema.py", line 2793, in create_all
tables=tables)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1478, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1471, in _optional_conn_ctx_manager
with self.contextual_connect() as conn:
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1661, in contextual_connect
self.pool.connect(),
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 272, in connect
return _ConnectionFairy(self).checkout()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 425, in __init__
rec = self._connection_record = pool._do_get()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 857, in _do_get
return self._create_connection()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 225, in _create_connection
return _ConnectionRecord(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 318, in __init__
self.connection = self.__connect()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 368, in __connect
connection = self.__pool._creator()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 80, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 283, in connect
return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.OperationalError: (OperationalError) unable to open database file None None
在 config.py 文件中
LOGFILE = '/tmp/ate.log' DEBUG = True TESTING = True THREADED = True DATABASE_URI = 'sqlite:////tmp/ate.db' SECRET_KEY = os.urandom(24)
因此,我在我的用户下创建了一个名为“tmp”的文件夹和一个名为“ate.db”的空文件。然后,再次运行它。它说
IOError:[Errno 2] 没有这样的文件或目录:'/home/kevin/log/ate.log'
然后,我创建了日志文件夹和日志文件。运行它,但什么也没发生
(venv)kevin@ubuntu:~/python/public_html$ python index.wsgi (venv)kevin@ubuntu:~/python/public_html$ python index.wsgi (venv)kevin@ubuntu:~/python/public_html$
如果成功,该网站应该在http://127.0.0.1:5000
/上可用。但是,它没有用。有谁知道为什么以及如何解决它?这些代码应该没问题,因为它现在可以在线获得。问题应该是本地问题。非常感谢你的帮助。
程序卡住的地方的代码
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
engine = None
db_session = None
Base = declarative_base()
def init_engine(uri, **kwards):
global engine
engine = create_engine(uri, **kwards)
return engine
def init_db():
global db_session
db_session = scoped_session(sessionmaker(bind=engine))
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
import models
Base.metadata.create_all(engine)