finding domain name

B

Bobby Roberts

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.
 
G

Gerhard Häring

Bobby said:
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("HTTP_HOST", None) or environ["SERVER_NAME"]

-- Gerhard
 
J

Joe Riopel

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.
 
B

Bobby Roberts

Depends on the technology/web framework. If you use WSGI, you should use
something like:

host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"]

-- Gerhard

Yeah i already tried environ("SERVER_NAME") but get a key error when i
do.
 
B

Bobby Roberts

Bobby said:
Depends on the technology/web framework. If you use WSGI, you should use
something like:
host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"]
-- 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).
 
B

Bruno Desthuilliers

Bobby Roberts a écrit :
Bobby said:
Depends on the technology/web framework. If you use WSGI, you should use
something like:
host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"]
-- 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).

Please don't compare apples to roller-skates. asp is a mix of libraries,
components and whatever, while Python is a language.
 
B

Bruno Desthuilliers

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 ?
 
B

Bobby Roberts

Bobby Roberts a écrit :



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.
 
G

Gabriel Genellina

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_environ() function)
 
B

Bruno Desthuilliers

Bobby Roberts a écrit :
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.hostname,
request.uri, request.path_info and request.filename. More informations here:

http://www.modpython.org/live/current/doc-html/pyapi-mprequest-mem.html

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 !-)
 
L

Lawrence D'Oliveiro

In message
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top