1

我正在尝试使用 mod_wsgi 在 apache 中运行烧瓶不安的应用程序。这适用于开发服务器。我已经阅读了我能找到的所有内容,但我所看到的答案似乎都不适合我。该应用程序正确处理非数据库请求,但当我尝试访问需要数据库访问权限的 url 时出现以下错误:

OperationalError: (OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 13] Permission denied)") None None

我已经使用我config和我的 flask-sqlalchemy 模型导入from flask import models(这是我的python代码:

import flask
import flask.ext.sqlalchemy
import flask.ext.restless
import sys

sys.path.insert(0, '/proper/path/to/application')

application = flask.Flask(__name__, static_url_path = "")
application.debug=True
application.config.from_object('config')

db = flask.ext.sqlalchemy.SQLAlchemy(application)

from app import models

# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(application, flask_sqlalchemy_db=db)

# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(models.Asset, methods=['GET'])

# start the flask loop
if __name__ == '__main__':
        application.run()

我假设 mod_wsgi 在查找config包含数据库访问详细信息的文件时没有问题,因为在读取配置时我没有收到错误,而且我也没有在from app import models.

到目前为止,我的研究使我相信这与存在于错误范围或上下文中的 sql-alchemy db 连接有关,并且可能因烧瓶不安的 API 管理器而变得复杂。我似乎无法绕过它。

4

1 回答 1

1

您在 Apache/mod_wsgi 下的代码将作为一个特殊的 Apache 用户运行。该用户可能没有连接到数据库所需的权限。

即使它显示“localhost”并且您认为这可能意味着正常的套接字连接,一些数据库客户端也会看到“localhost”并且会自动尝试使用 UNIX 套接字作为数据库连接。它可能无法访问该 UNIX 套接字连接。

或者,当通过 UNIX 套接字连接时,它会尝试验证 Apache 用户是否具有访问权限,但如果数据库尚未设置为允许 Apache 用户访问,则可能会失败。

考虑使用 mod_wsgi 的守护程序模式,并将守护程序模式配置为以与 Apache 用户不同的用户身份运行,并且您知道该用户可以访问数据库。

于 2014-06-04T10:46:21.180 回答