Python: CGI program wants to know the IP address of the calling web page

From here:

# When run as a cgi script, this will print the client's IP address.

import html
import os

print("Content-type: text/html")
print("")

print html.escape(os.environ["REMOTE_ADDR"])

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.