finding domain name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bobby Roberts

    finding domain name

    hi group. I'm new to python and need some help and hope you can
    answer this question. I have a situation in my code where i need to
    create a file on the server and write to it. That's not a problem if
    i hard code the path. However, the domain name needs to be dynamic so
    it is picked up automatically. The path to our websites is

    home/sites/xxxxx/

    where xxxxx represents the domain name.

    How can I find the domain name of the current url being viewed.
  • =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    #2
    Re: finding domain name

    Bobby Roberts wrote:
    hi group. I'm new to python and need some help and hope you can
    answer this question. I have a situation in my code where i need to
    create a file on the server and write to it. That's not a problem if
    i hard code the path. However, the domain name needs to be dynamic so
    it is picked up automatically. The path to our websites is
    >
    home/sites/xxxxx/
    >
    where xxxxx represents the domain name.
    >
    How can I find the domain name of the current url being viewed.
    Depends on the technology/web framework. If you use WSGI, you should use
    something like:

    host_name = environ.get("HT TP_HOST", None) or environ["SERVER_NAM E"]

    -- Gerhard

    Comment

    • Bobby Roberts

      #3
      Re: finding domain name

      Depends on the technology/web framework. If you use WSGI, you should use
      something like:
      >
      host_name = environ.get("HT TP_HOST", None) or environ["SERVER_NAM E"]
      >
      -- Gerhard
      Yeah i already tried environ("SERVER _NAME") but get a key error when i
      do.

      Comment

      • Joe Riopel

        #4
        Re: finding domain name

        On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <tchendrix@gmai l.comwrote:
        hi group. I'm new to python and need some help and hope you can
        answer this question. I have a situation in my code where i need to
        create a file on the server and write to it. That's not a problem if
        i hard code the path. However, the domain name needs to be dynamic so
        it is picked up automatically. The path to our websites is
        >
        home/sites/xxxxx/
        >
        where xxxxx represents the domain name.
        >
        How can I find the domain name of the current url being viewed.
        I would guess that a pretty simple regular expression might do it.

        Comment

        • Bobby Roberts

          #5
          Re: finding domain name

          On Sep 23, 8:54 am, "Joe Riopel" <goo...@gmail.c omwrote:
          On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <tchend...@gmai l.comwrote:
          hi group.  I'm new to python and need some help and hope you can
          answer this question.  I have a situation in my code where i need to
          create a file on the server and write to it.  That's not a problem if
          i hard code the path.  However, the domain name needs to be dynamic so
          it is picked up automatically.  The path to our websites is
          >
          home/sites/xxxxx/
          >
          where xxxxx represents the domain name.
          >
          How can I find the domain name of the current url being viewed.
          >
          I would guess that a pretty simple regular expression might do it.
          can you explain?

          Comment

          • Bobby Roberts

            #6
            Re: finding domain name

            On Sep 23, 9:10 am, Tino Wildenhain <t...@wildenhai n.dewrote:
            Bobby Roberts wrote:
            Depends on the technology/web framework. If you use WSGI, you should use
            something like:
            >
            host_name = environ.get("HT TP_HOST", None) or environ["SERVER_NAM E"]
            >
            -- Gerhard
            >
            Yeah i already tried environ("SERVER _NAME") but get a key error when i
            do.
            >
            You could output the whole environ to see what you get and how it is called.
            >
            I'd recommend however to check that you are using a configured value and
            not something sent by the client if you are going to use it during
            filesystem lookup.
            >
            Regards
            Tino
            >
             smime.p7s
            4KViewDownload
            evidently the environ dictionary is off limits on our server. It can't
            be that tough in python to get the current complete url being viewed.
            It's a snap in asp(which is my background).

            Comment

            • Bruno Desthuilliers

              #7
              Re: finding domain name

              Bobby Roberts a écrit :
              On Sep 23, 9:10 am, Tino Wildenhain <t...@wildenhai n.dewrote:
              >Bobby Roberts wrote:
              >>>Depends on the technology/web framework. If you use WSGI, you should use
              >>>something like:
              >>>host_name = environ.get("HT TP_HOST", None) or environ["SERVER_NAM E"]
              >>>-- Gerhard
              >>Yeah i already tried environ("SERVER _NAME") but get a key error when i
              >>do.
              >You could output the whole environ to see what you get and how it is called.
              >>
              >I'd recommend however to check that you are using a configured value and
              >not something sent by the client if you are going to use it during
              >filesystem lookup.
              >>
              >Regards
              >Tino
              >>
              > smime.p7s
              >4KViewDownlo ad
              >
              evidently the environ dictionary is off limits on our server.
              ???
              It can't
              be that tough in python to get the current complete url being viewed.
              It's a snap in asp(which is my background).
              Please don't compare apples to roller-skates. asp is a mix of libraries,
              components and whatever, while Python is a language.

              Comment

              • Bobby Roberts

                #8
                Re: finding domain name

                On Sep 23, 1:23 pm, Bruno Desthuilliers
                <bdesth.quelque ch...@free.quel quepart.frwrote :
                Bobby Roberts a écrit :
                >
                hi group.  I'm new to python and need some help and hope you can
                answer this question.  I have a situation in my code where i need to
                create a file on the server and write to it.  That's not a problem if
                i hard code the path.  However, the domain name needs to be dynamic so
                it is picked up automatically.  The path to our websites is
                >
                home/sites/xxxxx/
                >
                where xxxxx represents the domain name.
                >
                How can I find the domain name of the current url being viewed.
                >
                What are you using exactly ? cgi ? wsgi ? Else ?
                mod python over an in-house framework written years ago without
                documentation so it's not the easiest thing to navigate. We will be
                moving to django this fall.

                Comment

                • Gabriel Genellina

                  #9
                  Re: finding domain name

                  En Tue, 23 Sep 2008 09:37:44 -0300, Bobby Roberts <tchendrix@gmai l.com>
                  escribió:
                  hi group. I'm new to python and need some help and hope you can
                  answer this question. I have a situation in my code where i need to
                  create a file on the server and write to it. That's not a problem if
                  i hard code the path. However, the domain name needs to be dynamic so
                  it is picked up automatically. The path to our websites is
                  >
                  home/sites/xxxxx/
                  >
                  where xxxxx represents the domain name.
                  >
                  How can I find the domain name of the current url being viewed.
                  That info comes from the "Host" request field, and whether it's available
                  or not depends on the web framework in use; for a plain old CGI script, it
                  depends on the server configuration. Look at the HTTP_HOST environment
                  variable (accessing os.environ, or with the cgi.print_envir on() function)

                  --
                  Gabriel Genellina

                  Comment

                  • Bruno Desthuilliers

                    #10
                    Re: finding domain name

                    Bobby Roberts a écrit :
                    On Sep 23, 1:23 pm, Bruno Desthuilliers
                    <bdesth.quelque ch...@free.quel quepart.frwrote :
                    >Bobby Roberts a écrit :
                    >>
                    >>hi group. I'm new to python and need some help and hope you can
                    >>answer this question. I have a situation in my code where i need to
                    >>create a file on the server and write to it. That's not a problem if
                    >>i hard code the path. However, the domain name needs to be dynamic so
                    >>it is picked up automatically. The path to our websites is
                    >>home/sites/xxxxx/
                    >>where xxxxx represents the domain name.
                    >>How can I find the domain name of the current url being viewed.
                    >What are you using exactly ? cgi ? wsgi ? Else ?
                    >
                    mod python
                    Ok. So the informations you're looking for should be accessible as
                    attributes of the request object that get passed to your request
                    handler. Attributes of interest here are mostly request.hostnam e,
                    request.uri, request.path_in fo and request.filenam e. More informations here:



                    over an in-house framework written years ago
                    Mmm... Then you might want to checkout which version of mod_python
                    you're using, and make sure you read the corresponding doc...

                    FWIW, there's also a mod_python mailing-list, so I suggest you seek
                    further assistance wrt/ mod_python specific stuff there. Of course,
                    questions about the Python language and it's standard lib are welcome here.
                    without
                    documentation
                    use the code, young jedi !-)
                    so it's not the easiest thing to navigate. We will be
                    moving to django this fall.

                    Comment

                    • Lawrence D'Oliveiro

                      #11
                      Re: finding domain name

                      In message
                      <09637faf-75d8-4af0-b835-3b5a67132996@y2 1g2000hsf.googl egroups.com>, Bobby
                      Roberts wrote:
                      evidently the environ dictionary is off limits on our server.
                      Why?
                      It can't
                      be that tough in python to get the current complete url being viewed.
                      It's a snap in asp(which is my background).
                      Unless, of course, the relevant information was off limits on your server.

                      Comment

                      Working...