I am new to Python programming.
I am stuck on what should be a simple procedure. I have a small and basic Python program that is called as CGI program by a web page.
All that I want to do is extract the IP address from the HTTP header fields.
For example, in PHP, this would be the value of $_SERVER['REMOTE_ADDR'].
I paid my dues by doing a search, and I came up with the fact that I need to use web.ctx.ip, but when I use that bit in code, there is an exception. I probably need to import something. I’ve tried the following individual imports without success:
import web
import webapi as web
I’d appreciate a complete snippet of code that demonstrates what I need to import. My Python CGI program is running on a Linux box that has a basic Python version 2.4.3 installed. Do I need to install something else?
From here:
The search was for "python cgi get ip address" and it was the first result. This answer is for generic Python CGI, if you’re using some other interface / library then it might be different. It is the exact analog of the PHP version, however, as you can see.