简体   繁体   English

我们如何测试服务器地址

[英]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.

相关问题 我们如何将测试用例从 Microsoft Foundation Server (TFS) 导出为 excel 格式? - How can we export test cases from Microsoft foundation server(TFS) to an excel format? 我怎么知道服务器的IP地址? - How can I know the ip address of the server? 我们如何设置一个变量以便它可以在不同的测试套件中使用? - How can we set a variable such that it can be used in a different test suite? 如何在Python鼻子测试中控制函数执行的顺序 - How can we control the sequence of function execution in Python Nose test 我们如何使用 Django LiveServerTestCase 和 Selenium 来测试 https url - How can we use Django LiveServerTestCase with Selenium to test https urls 我们如何从python文本中提取特定测试 - How can we extract specific test from the text in python 在RobotFramework中,如何在Linux中将一个测试套件的价值用于另一个测试套件? - In RobotFramework, how can we use value of one test suite into another test suite in linux? 我们如何将 Pandas dataframe 中的所有内容插入 SQL 服务器中的表中? - How can we insert everything in a Pandas dataframe to a table in SQL Server? 我们可以在xml rpc服务器中注册多少个类/实例? - how many classes/instances can we register into xml rpc server? 我们如何使用 python 驱动程序连接到远程 Cassandra 服务器 - How can we connect to remote Cassandra server with python driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM