简体   繁体   中英

How can we test the address of the server

I recover the address of the server with that command : socket.gethostbyname(socket.gethostname())

So, in the file1.py I have :

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 :

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

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'. And the IP of the 'localhost' is always '127.0.0.1'.

See also: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM