Tôi đang chạy chương trình từ một người khác, những người bất tiện, yêu cầu trợ giúp. Chương trình là một trang web. Cuối máy chủ được viết bằng python và bình (mô-đun, http://flask.pocoo.org/). Chương trình đã được chạy thành công trên máy chủ. Những gì tôi cần làm là sửa đổi một cái gì đó trên đó. Vì máy chủ sản xuất không được phép thử nghiệm, tôi đã thử nghiệm nó trong máy chủ phát triển cục bộ thông qua bình. Tuy nhiên, tôi không thể chạy ngay cả chương trình gốc. Dưới đây là từ python.sqlalchemy.exc.OperationalError: (OperationalError) không thể mở tệp cơ sở dữ liệu Không có Không
(venv)[email protected]:~/python/public_html$ python index.wsgi
Traceback (most recent call last): File "index.wsgi", line 6, in from app import app as application
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
Trong tập tin config.py
LOGFILE = '/tmp/ate.log' DEBUG = True TESTING = True THREADED = True DATABASE_URI = 'sqlite:////tmp/ate.db' SECRET_KEY = os.urandom(24)
Do đó, tôi đã tạo ra một thư mục có tên "tmp" dưới người dùng của tôi và một tập tin rỗng gọi là "ate.db". Sau đó, chạy lại. Nó cho biết
IOError: [Errno 2] No such file or directory: '/home/kevin/log/ate.log'
Sau đó, tôi đã tạo thư mục nhật ký và tệp nhật ký. Hãy chạy, nhưng không có gì xảy ra như
(venv)[email protected]:~/python/public_html$ python index.wsgi (venv)[email protected]:~/python/public_html$ python index.wsgi (venv)[email protected]:~/python/public_html$
Nếu thành công, trang web sẽ có sẵn trên http://127.0.0.1:5000
/. Tuy nhiên, nó không hoạt động. Có ai biết tại sao và làm thế nào để giải quyết nó? Các mã nên được sử dụng tốt vì nó có sẵn trực tuyến. Vấn đề phải là một vấn đề địa phương. Cảm ơn rất nhiều vì sự giúp đỡ của bạn.
Mã về nơi chương trình được bị mắc kẹt
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)
được có nghĩa là để được 4 '////' sau ' sqlite: 'hoặc chỉ 3? Ngoài ra '/ tmp/ate.db' có nghĩa là nó được lưu trữ trong'/tmp' và không phải 'tmp'. Trừ khi bạn đang chroot'ed của khóa học. –
Nó có nghĩa là 4. Tôi nghĩ rằng đó là vấn đề của môi trường địa phương của tôi bởi vì nó có thể được chạy trong máy tính và máy chủ khác. Tuy nhiên, tôi không biết những gì tôi bỏ lỡ trong máy tính xách tay của tôi. – user2677756
Có thể đáng để cung cấp mã xung quanh nơi dấu vết ngăn xếp trỏ đến –