简体   繁体   中英

cannot access a simple bottle web page in Raspberry Pi from PC

I followed the guide https://bottlepy.org/docs/dev/tutorial.html on Raspberry Pi with the following example

from bottle import route, run
@route('/hello')
def hello():
    return "Hello World!"
run(host='0.0.0.0', port=81, debug=True)

Then I run the python script sudo python hello.py

The web page http://<IP address>:81 is not available, where <IP address> is the IP address of the raspberrry pi.

Running sudo netstat --tcp --udp --listening --program

I obtain

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp   0      0     < IP address >:81        *:*                     LISTEN      26308/python`

You're using the wrong port. (It looks like you may have copied the bottle "hello world" example without understanding what it's doing.) To use port 81, make this change:

run(host='0.0.0.0', port=81, debug=True)

Alternatively, just keep your code the way it is and access it at http://<IP address>:8080/hello

One reason to prefer port 8080 over 81 is that 81 requires root (sudo).

iptable is blocking incoming traffic on port 81.

It works after the command sudo iptables -A INPUT -p tcp --dport 81 -j ACCEPT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM