PermissionError: [Errno 13] Permission denied while running a server-side CGI scripts coded in Python

PermissionError: [Errno 13] Permission denied while running a server-side CGI scripts coded in Python

我正在尝试 运行 在 python 中编码的服务器端 cgi 脚本,但在 运行 运行它时出现以下错误。

Traceback (most recent call last):
  File "webserver.py", line 16, in <module>
    srvrobj = HTTPServer(srvraddr,CGIHTTPRequestHandler)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 449, in __init__
    self.server_bind()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 463, in server_bind
    self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied

这是我正在尝试的脚本 运行。

"""
Implement an HTTP web server in Python that knows how to run server-side
CGI scripts coded in Python; serves files and scripts from current working
dir; Python scripts must be stored in webdir\cgi-bin or webdir\htbin;

"""

import os,sys
from http.server import HTTPServer, CGIHTTPRequestHandler

webdir = '.'
port = 80       #default http://localhost/, else use http://localhost:xxxx/

os.chdir(webdir)
srvraddr  = ("",port)
srvrobj = HTTPServer(srvraddr,CGIHTTPRequestHandler)
srvrobj.serve_forever()

如有任何帮助,我们将不胜感激。提前致谢。

使用这个

chmod 777 script_name,

然后执行脚本,如果再次失败则使用

sudo python script_name

或查看如何 运行 在您各自的操作系统上使用管理员权限编写脚本。