Flask PermissionError:[Errno 13]权限被拒绝

时间:2019-04-24 13:19:23

标签: python python-3.x flask

我正在尝试使用/opt/mount1/python35/bin/python3.5 notification.py运行Flask应用程序,但出现以下错误:

WARNING:tensorflow:From /opt/mount1/python35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
 * Serving Flask app "notification" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "notification.py", line 19, in <module>
    app.run(debug=True)
  File "/opt/mount1/python35/lib/python3.5/site-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/opt/mount1/python35/lib/python3.5/site-packages/werkzeug/serving.py", line 988, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/opt/mount1/python35/lib/python3.5/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/opt/mount1/python35/lib/python3.5/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/opt/mount1/python35/lib/python3.5/subprocess.py", line 247, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/opt/mount1/python35/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/opt/mount1/python35/lib/python3.5/subprocess.py", line 1289, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
  

我已对flask应用程序文件夹授予了递归777权限。

从上面的堆栈跟踪中,我不确定出了什么问题。

任何帮助将不胜感激。谢谢!


更新

我尝试使用CentOS 7.6的核心python(即python 2.7 )运行Flask应用,并且有效!

我不确定为什么不适用于从RPM安装到路径/opt/mount1/python35的python 3.5.6 版本。

2 个答案:

答案 0 :(得分:2)

错误13(您的权限错误)通常可以通过更改端口号来解决。低于1024的TCP / IP端口号是已注册或“特权”的端口号-不允许用户在其上运行服务器。根据显示的第一条警告消息(关于生产环境中的服务器),我的猜测是您在低端口号(可能是80)上运行应用程序,但是如果您在其他端口号(例如4000或类似的端口)上运行应用程序(超过1024个),您将避免此错误。

您可能会发现this link有用

节选:

import socket

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 65432        # Port to listen on (non-privileged ports are > 1023)

答案 1 :(得分:1)

由于我已经在不同的路径中分别安装了Python 3.5,因此必须在文件顶部放置以下 shebang 来解决此问题:

#!/opt/mount1/python35/bin/python3.5