[英]How can we test the address of the server
I recover the address of the server with that command : socket.gethostbyname(socket.gethostname())
我使用以下命令恢复服务器的地址:
socket.gethostbyname(socket.gethostname())
So, in the file1.py I have : 因此,在file1.py中,我有:
def main( server_IP, name, version, install_path):
template = open('html.py').read()
c = string.Template(template).substitute(
name = name,
version = version,
install_path = install_path,
os = user_os,
user_name = user_login,
server_IP = socket.gethostbyname(socket.gethostname())
)
in html.py : 在html.py中 :
<form name="sendData" method="get" action="http://${server_IP}/cgi/scriptGet.py">
When I test this in my own computer, I have 127.0.0.1/cgi....... ( actually : The connection failed when this page is displayed). 在我自己的计算机上测试时,我有127.0.0.1/cgi .......(实际上:显示此页面时连接失败)。
How can I be sure to recover the address of the server ? 如何确定恢复服务器地址?
the server code 服务器代码
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = ["/cgi"]
httpd = server(server_address, handler)
httpd.serve_forever()
Regarding your problem: 关于您的问题:
The code does what is expected by it. 该代码完成了预期的工作。 If you run this on your home machine, the hostname returned by `socket.gethostname()' is 'localhost'.
如果在家用计算机上运行此命令,则`socket.gethostname()'返回的主机名是'localhost'。 And the IP of the 'localhost' is always '127.0.0.1'.
并且“本地主机”的IP始终为“ 127.0.0.1”。
See also: http://en.wikipedia.org/wiki/Localhost 另请参阅: http : //en.wikipedia.org/wiki/Localhost
If the connection fails, then there must be an error on the server side. 如果连接失败,则服务器端必须有一个错误。 That means the URL is good but something breaks and you should see an error in the error log or the terminal where you started the server.
这意味着该URL是好的,但是有些地方中断了,您应该在错误日志或启动服务器的终端中看到错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.