python - 对 linux 服务器的 ajax 请求有时会返回答案,有时会返回错误 500

标签 python flask centos gunicorn

我在 centos 机器上有一个带有 gunicorn 和 flask 的 python 应用程序。我通过以下方式从另一台机器访问应用程序:

http://host:port/nameOfFunction?path=https://site/directory1/directory2/directory3/file.pdf

路径是正确的,因为它有效。当我多次进入同一条路径时,有时它会起作用,而另一些则不起作用。

我正在使用 gunicorn(使用以下命令):
gunicorn -b 0.0.0.0:8080 start:app

开始我的申请。当答案返回时,显示 gunicorn 的屏幕会打印一些我用来查看一些信息的代码。
当它返回错误 500 时,根本不会打印 start 的代码。

我不知道这是什么原因。

代码的开头是:
@app.route("/call", methods=['POST', 'GET'])
def call():
   print '\n============================BEGINS======================\n'

   path =request.args.get('path')
   newPath = path.rsplit('/',1)[1]
   directoriesRoot(root)
   directoriesRoot(pdfs)

   parameters = ["curl", path.replace(' ','%20'), '--output',pdfs+newPath]

   p = subprocess.Popen(parameters, stdout=subprocess.PIPE)
   output, err = p.communicate()

  if err:
    return 'ERROR'

   person= functionSecundaryWithNoImportance([newPath])
   return jsonify(person) 

有人有一些线索或已经通过了类似的问题?

最佳答案

在 user3788685 的帮助下,我发现我的 python 应用程序位于端口 8080 上(可能 apache 的默认端口之一是 8080),因此它发生冲突。有时它指向 python,其他指向 apache。所以我将我的 python 应用程序的端口更改为 1234:

gunicorn -b 0.0.0.0:1234 start:app

现在作为一个魅力!

关于python - 对 linux 服务器的 ajax 请求有时会返回答案,有时会返回错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49887159/

相关文章:

python - 两个看似相同的 unicode 字符串在使用 repr() 时结果是不同的,但我该如何解决这个问题?

python - ORA-03135 连接在尝试使用 python 和 cx_Oracle 模块连接到数据库时失去联系

python - 无法使用 Python 导出 Cassandra 表

python - 构建大型 Flask 应用程序?

linux - 如何在 VirtualBox 上安装 CentOS 时配置互联网

linux - 为什么 grep 在 Debian 和 CentOs 中的工作方式不同?

python - 当 continue 命中时,是否有一种 Pythonic 方式在 'else' 循环中激活 'for'?

python-3.x - 如何在线程中运行 Flask SocketIO?

python - 如何使用 Flask 在 slack 应用程序中运行对话框?

linux - FFMPEG 命令仍然指的是旧版本