【发布时间】:2020-05-10 16:42:08
【问题描述】:
我有一个在 apache 服务器上运行的 python flask web 应用程序。 flask 应用程序只是一个函数,它返回我从 postgres 数据库中获得的值。
@app.route('/')
def hello_world():
import psycopg2
db_conn_string = ("dbname=" + "xxx"
+ " user=" + "xxx"
+ " host=" + "xxx"
+ " password=" + "xxx")
db_connection = psycopg2.connect(db_conn_string)
cursor = db_connection.cursor()
cursor.execute("SELECT * FROM XXX")
return cursor.fetchall()
当我运行这个应用程序时,我会在浏览器上看到这个:
我查看了/var/log/apache2/error.log下的日志,错误是:
[Fri Jan 24 10:34:34.676561 2020] [core:notice] [pid 15644:tid 139639322680256] AH00051: child pid 15972 exit signal Segmentation fault (11), possible coredump in /etc/apache2
有趣的是,当我将 return 语句更改为只返回一个 hello world 时,它运行得很好,而且我没有看到任何错误。所以我的假设是错误是由于 apache web 应用程序试图连接到 postgres 数据库。我检查了数据库的凭据,那里没有任何问题。我不知道如何解决这个问题。
编辑:具有相同代码的测试 python 程序可以工作,我能够检索数据。
【问题讨论】:
-
在 Python 测试程序中运行函数会得到什么结果?
-
@Bodo 是的,具有相同代码的 python 程序可以工作,我能够连接到数据库并检索数据。
-
cursor.fetchall()返回一个元组列表。我猜调用函数没有准备好处理那种结果。 -
@ArchitVerma 请edit 您的问题并在那里添加所有信息,而不是在 cmets 中回答。请展示正在运行的 Python 程序及其输出。
-
@tripleee 我认为这不是问题所在。即使尝试从列表中仅返回一个值,我也会收到相同的错误。
标签: python linux postgresql python-2.7 apache