0

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()
Kasper
  • 49
  • 7
  • According to [this question](http://stackoverflow.com/questions/4271740/how-can-i-use-python-to-get-the-system-hostname), the code is correct. What exactly do you mean "connection failed when page is displayed"? The sentence is confusing. Please make sure you use the correct tense in English. – Aaron Digulla Jul 29 '14 at 13:27
  • The code is highly confusing: What are the arguments the main takes? Where do they come from? And how does the html.py look like before you used substitute() on it? – loli Jul 29 '14 at 13:30
  • @AaronDigulla : When I click on "ok", it opens the next page with the good URL, but the connection is failed, I don't know why :( ( but I think It's not a big problem). – Kasper Jul 29 '14 at 14:35
  • @loli : I execute my script in command line, html.py in only a html code when I display my variables .... – Kasper Jul 29 '14 at 14:36
  • @AaronDigulla : Yes the code is good, but now, I want to know If anyone test this application, it returns in thr URL the address of the server .. – Kasper Jul 29 '14 at 14:38
  • 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. – Aaron Digulla Jul 29 '14 at 15:14
  • When I run this at a server, I get
    , which corresponds to my computers IP. Could you please provide a minimal working example (without name, version, or main(...), etc.) and the the substitution results for your local PC as well as server?
    – loli Jul 30 '14 at 08:14
  • @loli : I have edited the post and added the code of the server .... , so, when you test the code you see your IP address ? That's good ? because !i have a database stored in the server and the client must access to the next page with the "ok" button, when he click on this button ( the data are stored in the database, so the client he's connecting to the server and the server return the next page) you know ? But when the client ask the next page to the server he makes a connection to the server and the server must to return he's address and the good file, that's what I want. – Kasper Jul 30 '14 at 10:26
  • @Kasper: I would suggest you re-formulate the whole question, including a detailed account of what you want to achieve and where exactly the problem arises. How you start / configure the server does not really seem to matter. Try to keep the words simple and probably provide a little image happens where and how the different parties interact. Your English is sometimes a little bit confusing and hard to understand. – loli Aug 08 '14 at 10:26

2 Answers2

0

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

loli
  • 395
  • 3
  • 10
0

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820