Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:49:08+00:00 2026-05-24T12:49:08+00:00

I am new to Python programming. I am stuck on what should be a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:49:09+00:00Added an answer on May 24, 2026 at 12:49 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to network programming but old to Python. I have a simple
while learning some basic programming with python, i found web.py. i got stuck with
I am new to C++/Python mixed language programming and do not have much idea
It seems that most new programming languages that have appeared in the last 20
I have a new web app that is packaged as a WAR as part
I'm totaly new to Python (and programming), so I'm stuck with some csv readings.
I'm new to python programming and using ubuntu to do so. In a program
i have a question because i am fairly new to python, socket programming and
I have a method in c++ that gets called from python and needs to
Im new to python programming and need some help with some basic file I/O

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.