python -m SimpleHTTPServer - Listening on 0.0.0.0:8000 but http://0.0.0.0:8000/test.html gives “Page Not Found”

前端 未结 10 1316
情歌与酒
情歌与酒 2020-12-29 04:54

After cding to my folder I enter

python -m SimpleHTTPServer

and get

Serving HTTP on 0.0.0.0 port 8000 ...
<
相关标签:
10条回答
  • 2020-12-29 05:32

    Run ifconfig on Linux or ipconfig on Windows to find the ip address of the server.

    $ sudo ifconfig
    wlan0     Link encap:Ethernet  HWaddr 30:3a:64:b3:be:6a  
              inet addr:192.168.1.103  Bcast:192.168.1.255  Mask:255.255.255.0
    

    Here in case the url would be:

    http://192.168.1.103:8000/test.html

    0 讨论(0)
  • 2020-12-29 05:32

    try this in python3

    python -m http.server 8000 --bind 127.0.0.1
    

    and in your browser this url:

    http://127.0.0.1:8000/

    0 讨论(0)
  • 2020-12-29 05:35

    Have you tried http://127.0.0.1:8000/ ?

    :)

    0 讨论(0)
  • 2020-12-29 05:41

    I think the other two answers are trying to make it clear that 0.0.0.0 is not the URL you should be visiting. When a Python web server (like cherrypy for instance) says it is serving on 0.0.0.0 it means it is listening for all TCP traffic that ends up at that machine no matter the hostname or IP that was requested. But, if you change it such that the socket listens on 127.0.0.1 or 'localhost', then unless the request was specifically to that IP/hostname, it won't respond to the request. For example, many times you can use your machine name instead of localhost (ubuntu allows this for example). If your machine name is 'brian' and you have a server listening on 0.0.0.0:8080, you should be able to reach that server with http://brian:8080. But if that server is listening on 'localhost', even though 'brian' is set to point to 'localhost', the server won't receive the message.

    You also need to be sure the file really is in the directory you are running the command from. Otherwise, the 404 response is actually correct :)

    Good luck!

    0 讨论(0)
提交回复
热议问题