python -m SimpleHTTPServer-侦听0.0.0.0:8000,但http://0.0.0.0:8000/test.html给出“找不到页面" [英] python -m SimpleHTTPServer - Listening on 0.0.0.0:8000 but http://0.0.0.0:8000/test.html gives "Page Not Found"

查看:569
本文介绍了python -m SimpleHTTPServer-侦听0.0.0.0:8000,但http://0.0.0.0:8000/test.html给出“找不到页面"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进入我的文件夹后,我输入

After cding to my folder I enter

python -m SimpleHTTPServer

并获得

Serving HTTP on 0.0.0.0 port 8000 ...

回复.但是当我按下http://0.0.0.0:8000/test.html时,出现页面未找到错误.

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

我也尝试过

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

摘自此问题

当我点击ls时,我可以看到文件和目录.有人知道我在做什么错吗?

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

推荐答案

我认为其他两个答案试图使您清楚地知道0.0.0.0不是您应该访问的URL.当Python Web服务器(例如,cherrypy)表示正在使用0.0.0.0时,这意味着它正在侦听最终到达该计算机的所有TCP通信,无论请求的主机名或IP如何.但是,如果将其更改为使套接字侦听127.0.0.1或"localhost",则除非该请求专门针对该IP/主机名,否则它将不会响应该请求.例如,很多时候您可以使用计算机名代替localhost(例如,ubuntu允许使用此名称).如果您的计算机名称是"brian",并且您有一个正在侦听0.0.0.0:8080的服务器,则应该可以通过 http访问该服务器://brian:8080 .但是,即使该服务器在"localhost"上侦听,即使将"brian"设置为指向"localhost",该服务器也不会收到该消息.

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.

您还需要确保文件确实在运行命令的目录中.否则,404响应实际上是正确的:)

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 :)

祝你好运!

这篇关于python -m SimpleHTTPServer-侦听0.0.0.0:8000,但http://0.0.0.0:8000/test.html给出“找不到页面"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆