权限问题 - PermissionError [Errno 13] 权限被拒绝

时间:2021-03-27 17:31:24

标签: python raspberry-pi bottle

我正在尝试在树莓派上使用 Bottle 和 python 3 来基本上将网页加载到 pi 的 IP 地址上。这应该允许我将 pi 的 IP 输入到我的笔记本电脑上的浏览器和网页上的点击按钮以提供输入到我的程序中。但是,当我尝试此操作时,出现权限错误,提示权限被拒绝

这是代码、网络代码和错误

代码:

from bottle import route, run, template, request
import time

IP_ADDRESS = '192.168.1.8' #Change this to the IP of your Pi

#Handler for the home page
@route('/')
def index():
    cmd = request.GET.get('command', '')
    if cmd == 'f':
        print('Forward' )
    elif cmd == 'l':
        print('Left' )
    elif cmd == 's':
        print('Stop' )
    elif cmd == 'r':
        print('Right' )
    elif cmd == 'b':
        print('Reverse' )
    return template('home.tpl')

#Start the webserver running on port 80
try:
    run(host=IP_ADDRESS, port=80)
finally:
    print('done')

网络代码(home.tpl):

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<style>
.controls {
    width: 150px;
    font-size: 32pt;
    text-align: center;
    padding: 15px;
    background-color: green;
    color: white;
}
</style>

<script>
function sendCommand(command)
{
    $.get('/', {command: command});
}
function keyPress(event){
    code = event.keyCode;
    if (code == 119) {
        sendCommand('f');
    }
    else if (code == 97) {
        sendCommand('l');
    }
    else if (code == 115) {
        sendCommand('s');
    }
    else if (code == 100) {
        sendCommand('r');
    }
    else if (code == 122) {
        sendCommand('b');
    }
}
$(document).keypress(keyPress);
</script>
</head>
<body>
<h1>Web Rover</h1>
<table align="center">
<tr><td></td><td class="controls" onClick="sendCommand('f');">W</td><td></td></tr>
<tr><td  class="controls" onClick="sendCommand('l');">A</td>
    <td  class="controls" onClick="sendCommand('s');">S</td>
    <td  class="controls" onClick="sendCommand('r');">D</td>
</tr>
<tr><td></td><td  class="controls" onClick="sendCommand('b');">Z</td><td></td></tr>
</table>
</body>
</html>

错误:

Bottle v0.12.19 server starting up (using WSGIRefServer())...
Listening on http://192.168.1.8:80/
Hit Ctrl-C to quit.

done
Traceback (most recent call last):
  File "/home/pi/Desktop/bottle-0.12.19/Web Test.py", line 24, in <module>
    run(host=IP_ADDRESS, port=80)
  File "/home/pi/Desktop/bottle-0.12.19/bottle.py", line 3137, in run
    server.run(app)
  File "/home/pi/Desktop/bottle-0.12.19/bottle.py", line 2789, in run
    srv = make_server(self.host, self.port, app, server_cls, handler_cls)
  File "/usr/lib/python3.7/wsgiref/simple_server.py", line 153, in make_server
    server = server_class((host, port), handler_class)
  File "/usr/lib/python3.7/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.7/wsgiref/simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/lib/python3.7/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied

代码和网页代码在同一个文件夹中。我本来在用 Bottle 时遇到了问题,但后来我将这两个文件移动到了有 Bottle 的文件夹中,然后当我运行它时,它给出了上面的错误。

我尝试将 home.tpl 设为 home.html。当我在浏览器中打开 home.html 时,它正确显示了网络代码。当我在浏览器中打开 home.tpl 时,它只会给我显示在屏幕上的代码。如果我使用 home.tpl 或 home.html 运行 python 文件,则会显示相同的错误(是的,我在代码中将文件从 .tpl 更改为 .html)

有没有人知道任何可以帮助我解决这个问题的东西?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

没有管理员权限,您不能使用低于 1024(在您的情况下为 80)的任何端口。使用大于 1024 的端口(推荐)或使用提升的 (sudo) 权限运行脚本。