python -m SimpleHTTPServer - Listening on 0.0.0.0:

2019-03-14 17:23发布

After cding to my folder I enter

python -m SimpleHTTPServer

and get

Serving HTTP on 0.0.0.0 port 8000 ...

in reply. But when I hit http://0.0.0.0:8000/test.html I get a page not found error.

I've also tried

pushd /path/you/want/to/serve; python -m SimpleHTTPServer; popd

taken from this question

When I hit ls I can see the file and the directory. Anyone know what I'm doing wrong?

8条回答
家丑人穷心不美
2楼-- · 2019-03-14 18:01

You must type in the ip-address of the computer your connecting to for example 192.168.0.2:8000 Change that to the ip-address of your server.

查看更多
一纸荒年 Trace。
3楼-- · 2019-03-14 18:04

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/

查看更多
forever°为你锁心
4楼-- · 2019-03-14 18:07

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!

查看更多
beautiful°
5楼-- · 2019-03-14 18:08

You should use this link http://127.0.0.1:8000/ and can see all files there

查看更多
爷、活的狠高调
6楼-- · 2019-03-14 18:08
  1. create a directory e.g. mkdir HTTPServer_dir
  2. move inside the folder cd HTTPServer_dir
  3. typing the command (according to python version) python -m SimpleHTTPSever 8000 (or the port you want)
  4. go on a browser and type http://127.0.0.1:8000/

Done !!!

You could make a simple index.html page inside the HTTPServer_dir so you can see an html page instead of directory listing

查看更多
看我几分像从前
7楼-- · 2019-03-14 18:11

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

:)

查看更多
登录 后发表回答