python-3.x - PermissionError:[Errno 13] 运行以 Python 编码的服务器端 CGI 脚本时权限被拒绝
问题描述
我正在尝试运行用 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
或检查如何在您各自的操作系统上使用管理员权限运行脚本。
推荐阅读
- c - 您不能从函数内部重新分配 C 中的内存块吗?
- python - Plotly:如何自定义图例顺序?
- arrays - Swift 5:如何测试 AnyObject?它的值类型的变量?
- python - 如何删除 Django 中的操作错误?
- python - 修补程序滚动条不适用于画布小部件
- javascript - vue.js 道具没有在组件中呈现
- java - 我还能在 macOS 上使用 JDK 7 吗?
- python - “未找到版本‘GLIBCXX_3.4.26’”在 anaconda env 中运行 gdal 时出错
- react-native - flatlist 用阿拉伯语口吃
- c - 从C中的单链表中删除特定节点