Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36892 > unrolled thread
| Started by | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| First post | 2013-01-16 05:51 -0800 |
| Last post | 2013-01-19 17:53 -0800 |
| Articles | 15 on this page of 35 — 11 participants |
Back to article view | Back to comp.lang.python
Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-16 05:51 -0800
Re: Forcing Python to detect DocumentRoot Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-16 09:01 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-16 06:32 -0800
Re: Forcing Python to detect DocumentRoot Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-16 09:39 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-16 06:32 -0800
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-17 01:03 -0800
Re: Forcing Python to detect DocumentRoot rusi <rustompmody@gmail.com> - 2013-01-17 05:51 -0800
Re: Forcing Python to detect DocumentRoot Roy Smith <roy@panix.com> - 2013-01-17 09:09 -0500
Re: Forcing Python to detect DocumentRoot Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-17 10:14 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 05:02 -0800
Re: Forcing Python to detect DocumentRoot Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-18 08:28 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 10:58 -0800
Re: Forcing Python to detect DocumentRoot Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-18 14:11 -0500
Re: Forcing Python to detect DocumentRoot Chris Angelico <rosuav@gmail.com> - 2013-01-19 08:34 +1100
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-19 00:01 -0800
Re: Forcing Python to detect DocumentRoot Michael Torrie <torriem@gmail.com> - 2013-01-21 11:49 -0700
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-19 00:01 -0800
Re: Forcing Python to detect DocumentRoot Piet van Oostrum <piet@vanoostrum.org> - 2013-01-19 21:01 +0100
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-20 22:25 -0800
Re: Forcing Python to detect DocumentRoot Dave Angel <d@davea.name> - 2013-01-21 07:33 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-21 06:55 -0800
Re: Forcing Python to detect DocumentRoot Michael Torrie <torriem@gmail.com> - 2013-01-21 11:42 -0700
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-21 06:55 -0800
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 10:58 -0800
Re: Forcing Python to detect DocumentRoot Rodrick Brown <rodrick.brown@gmail.com> - 2013-01-18 08:41 -0500
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 12:49 -0800
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 12:49 -0800
Re: Forcing Python to detect DocumentRoot Michael Torrie <torriem@gmail.com> - 2013-01-21 08:46 -0700
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-21 08:02 -0800
Re: Forcing Python to detect DocumentRoot Michael Torrie <torriem@gmail.com> - 2013-01-21 11:36 -0700
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-21 08:02 -0800
Re: Forcing Python to detect DocumentRoot Piet van Oostrum <piet@vanoostrum.org> - 2013-01-21 20:05 +0100
Re: Forcing Python to detect DocumentRoot Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-18 05:02 -0800
Re: Forcing Python to detect DocumentRoot Barry Scott <barry@barrys-emacs.org> - 2013-01-19 11:40 +0000
Re: Forcing Python to detect DocumentRoot alex23 <wuwei23@gmail.com> - 2013-01-19 17:53 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-21 06:55 -0800 |
| Message-ID | <52e3e53e-f2fe-4e0f-a11d-1c6d52f39c36@googlegroups.com> |
| In reply to | #37184 |
Τη Δευτέρα, 21 Ιανουαρίου 2013 2:33:22 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε: > On 01/21/2013 01:25 AM, Ferrous Cranus wrote: > > > Τη Σάββατο, 19 Ιανουαρίου 2013 10:01:15 μ.μ. UTC+2, ο χρήστης Piet van Oostrum έγραψε: > > >> Ferrous Cranus <nikos.gr33k@gmail.com> writes: > > > > > While > > > > > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > > > > > that has also embedded this line: > > > > > > <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a> > > > > > > cannnot open the file normally. > > > > > > And the questions iw WHY since python script can open ANY filesystempath > > > file the user has access too. > > > > > > > As Piet has said,Python is NOT opening the file mail.png. When the html > > is sent to the browser, and the browser requests that image file, it's > > the server itself who figures out where the actual file is. Python > > isn't involved at all. > > > > -- > > DaveA Yes Dave so we need to remove <img src="/data/images/mail.png"> since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file.
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-01-21 11:42 -0700 |
| Message-ID | <mailman.758.1358793733.2939.python-list@python.org> |
| In reply to | #37197 |
On 01/21/2013 07:55 AM, Ferrous Cranus wrote: > Yes Dave so we need to remove <img src="/data/images/mail.png"> > since the apache cant see to open it and let Python open it which we > know it can because it has access to any system file the user has > access too. What are you trying to accomplish? I don't see how opening the file with python will do anything because as has been said many times on this thread, your python CGI generates html code which the browser then renders. Opening an image file with python will do nothing useful. > So if a python script can open any file the user has access too then > we need a "python way" of opening this file. Still don't understand why you want python to open the image file. What do you want python to do with it? It's running on a web server, so there's no screen for python to display the image too. Technically it is possible to have a script that opens the image and serves it up as a binary stream to the browser using the image content-type header, but it's way more efficient to serve up the file statically. And you'd have to have a proper link in the html code anyway, to refer to your image-serving CGI script. Methinks you're barking up the wrong tree with python opening the image file.
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-21 06:55 -0800 |
| Message-ID | <mailman.746.1358780141.2939.python-list@python.org> |
| In reply to | #37184 |
Τη Δευτέρα, 21 Ιανουαρίου 2013 2:33:22 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε: > On 01/21/2013 01:25 AM, Ferrous Cranus wrote: > > > Τη Σάββατο, 19 Ιανουαρίου 2013 10:01:15 μ.μ. UTC+2, ο χρήστης Piet van Oostrum έγραψε: > > >> Ferrous Cranus <nikos.gr33k@gmail.com> writes: > > > > > While > > > > > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > > > > > that has also embedded this line: > > > > > > <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a> > > > > > > cannnot open the file normally. > > > > > > And the questions iw WHY since python script can open ANY filesystempath > > > file the user has access too. > > > > > > > As Piet has said,Python is NOT opening the file mail.png. When the html > > is sent to the browser, and the browser requests that image file, it's > > the server itself who figures out where the actual file is. Python > > isn't involved at all. > > > > -- > > DaveA Yes Dave so we need to remove <img src="/data/images/mail.png"> since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file.
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-18 10:58 -0800 |
| Message-ID | <mailman.644.1358535537.2939.python-list@python.org> |
| In reply to | #36997 |
Τη Παρασκευή, 18 Ιανουαρίου 2013 3:28:10 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε: > DocumentRoot = os.environ['HOME'] + 'public_html' Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot?
[toc] | [prev] | [next] | [standalone]
| From | Rodrick Brown <rodrick.brown@gmail.com> |
|---|---|
| Date | 2013-01-18 08:41 -0500 |
| Message-ID | <mailman.629.1358516516.2939.python-list@python.org> |
| In reply to | #36994 |
[Multipart message — attachments visible in raw view] — view raw
On Friday, January 18, 2013, Ferrous Cranus wrote:
> Τη Πέμπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick
> έγραψε:
> > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <r...@panix.com<javascript:;>>
> wrote:
> >
> > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com<javascript:;>
> >,
> >
> >
> >
> > Ferrous Cranus <nikos...@gmail.com <javascript:;>> wrote:
> >
> >
> >
> > > When trying to open an html template within Python script i use a
> relative
> >
> > > path to say go one folder back and open index.html
> >
> > >
> >
> > > f = open( '../' + page )
> >
> > >
> >
> > > How to say the same thing in an absolute way by forcing Python to
> detect
> >
> > > DocumentRoot by itself?
> >
$ export DOCUMENT_ROOT=${HOME}/public _html
Then from python os.environ['DOCUMENT_ROOT'] will have the relative path.
I hope this helps.
> >
> >
> > Can you give us more details of what you're doing. Is there some web
> >
> > framework you're using? Can you post some code that's not working for
> >
> > you?
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> > Import os
> >
> > Then read os.environ['HOME']
> >
> >
> > This will give you the home directory of the user. in my case:
> >
> >
> > >>> os.environ['HOME']
> > '/home/jcg'
> > >>>
> >
> >
> > This is probably linux only, but that seems to be the environment you
> are working in .
>
> Yes my Python scripts exist in a linux web host.
>
> os.environ['HOME'] will indeed give the home directory of the user.
>
> to me /home/nikos/
>
> but i want a variable to point to
>
> /home/nikos/public_html whice is called DocumentRoot.
>
> is there avariable for that? i can't seem to find any...
> --
> http://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-18 12:49 -0800 |
| Message-ID | <4f5c4fda-87df-4897-8b0c-13c36d12d918@googlegroups.com> |
| In reply to | #36998 |
Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot?
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-18 12:49 -0800 |
| Message-ID | <mailman.651.1358542939.2939.python-list@python.org> |
| In reply to | #36998 |
Yes, iam using this and it works. One last thing: my python script file is located at /home/nikos/public_html/addon_domain/cgi-bin/ How python is able to run the following statement? f = open( '/home/nikos/public_html/' + page ) which is clearly levels up of addon domain's DocumentRoot?
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-01-21 08:46 -0700 |
| Message-ID | <mailman.750.1358783208.2939.python-list@python.org> |
| In reply to | #36994 |
On 01/18/2013 06:02 AM, Ferrous Cranus wrote: > Yes my Python scripts exist in a linux web host. > > os.environ['HOME'] will indeed give the home directory of the user. > > to me /home/nikos/ > > but i want a variable to point to > > /home/nikos/public_html whice is called DocumentRoot. Not it's not. There is nothing in the operating system that defines this. > is there avariable for that? i can't seem to find any... Not there's nothing in the operating system that specifies this. This is a convention that makes sense only to the apache daemon itself. If your python script is running as a CGI script, then apache will set environment variables that you can read with the os module. See the Apache docs for information on this.
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-21 08:02 -0800 |
| Message-ID | <70bb8ac8-8089-4882-b8c8-a8c26fb1ffdf@googlegroups.com> |
| In reply to | #37206 |
Ok i see its just a convention. Can you help on this: so we need to remove <img src="/data/images/mail.png"> since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file.
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-01-21 11:36 -0700 |
| Message-ID | <mailman.757.1358793397.2939.python-list@python.org> |
| In reply to | #37208 |
On 01/21/2013 09:02 AM, Ferrous Cranus wrote: > Ok i see its just a convention. Can you help on this: > > so we need to remove <img src="/data/images/mail.png"> since the > apache cant see to open it and let Python open it which we know it > can because it has access to any system file the user has access too. Is this link generated by your python CGI script? If so you'll have to work out some way for your python script to interact with Apache and ask it where the document root is. If this link is in static html, then you simply need to fix your html to make the link valid. Or maybe you need to modify your apache installation so that it knows where "/data" is using an alias directive in your apache config.
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-21 08:02 -0800 |
| Message-ID | <mailman.752.1358784132.2939.python-list@python.org> |
| In reply to | #37206 |
Ok i see its just a convention. Can you help on this: so we need to remove <img src="/data/images/mail.png"> since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. httpd cannot open this file because the location of the image is past the addon domain's Document Root. /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root /home/nikos/public_html/data/images/mail.png = where the image file is located and the python scipt is on: /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py So if a python script can open any file the user has access too then we need a "python way" of opening this file.
[toc] | [prev] | [next] | [standalone]
| From | Piet van Oostrum <piet@vanoostrum.org> |
|---|---|
| Date | 2013-01-21 20:05 +0100 |
| Message-ID | <m2r4lepd9z.fsf@cochabamba.vanoostrum.org> |
| In reply to | #37209 |
Ferrous Cranus <nikos.gr33k@gmail.com> writes: > Ok i see its just a convention. > Can you help on this: > > so we need to remove <img src="/data/images/mail.png"> since the apache cant see to open it and let Python open it which we know it can because it has access to any system file the user has access too. > > httpd cannot open this file because the location of the image is past the addon domain's Document Root. > > /home/nikos/public_html/cafebar-idea.gr = Addon's Domain Document Root > > /home/nikos/public_html/data/images/mail.png = where the image file is located > > and the python scipt is on: > > /home/nikos/public_html/cafebar-idea.gr/cgi-bin/counter.py > > So if a python script can open any file the user has access too then we need a "python way" of opening this file. So why don't you put the image at /home/nikos/public_html/cafebar-idea.gr/data/images/mail.png? -- Piet van Oostrum <piet@vanoostrum.org> WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4]
[toc] | [prev] | [next] | [standalone]
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-01-18 05:02 -0800 |
| Message-ID | <mailman.626.1358514153.2939.python-list@python.org> |
| In reply to | #36942 |
Τη Πέμπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε: > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <r...@panix.com> wrote: > > In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com>, > > > > Ferrous Cranus <nikos...@gmail.com> wrote: > > > > > When trying to open an html template within Python script i use a relative > > > path to say go one folder back and open index.html > > > > > > f = open( '../' + page ) > > > > > > How to say the same thing in an absolute way by forcing Python to detect > > > DocumentRoot by itself? > > > > Can you give us more details of what you're doing. Is there some web > > framework you're using? Can you post some code that's not working for > > you? > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Import os > > Then read os.environ['HOME'] > > > This will give you the home directory of the user. in my case: > > > >>> os.environ['HOME'] > '/home/jcg' > >>> > > > This is probably linux only, but that seems to be the environment you are working in . Yes my Python scripts exist in a linux web host. os.environ['HOME'] will indeed give the home directory of the user. to me /home/nikos/ but i want a variable to point to /home/nikos/public_html whice is called DocumentRoot. is there avariable for that? i can't seem to find any...
[toc] | [prev] | [next] | [standalone]
| From | Barry Scott <barry@barrys-emacs.org> |
|---|---|
| Date | 2013-01-19 11:40 +0000 |
| Message-ID | <mailman.690.1358600283.2939.python-list@python.org> |
| In reply to | #36892 |
On 16 Jan 2013, at 13:51, Ferrous Cranus <nikos.gr33k@gmail.com> wrote: > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? In the general case it is not possible. There is no single convention you can use to detect the top of a web site. If you always use apache httpd then read the value of DocumentRoot from httpd.conf Barry
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2013-01-19 17:53 -0800 |
| Message-ID | <fcec424b-6493-4568-a51d-ccd17cc21b6d@rm7g2000pbc.googlegroups.com> |
| In reply to | #36892 |
On Jan 16, 11:51 pm, Ferrous Cranus <nikos.gr...@gmail.com> wrote: > When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html > > f = open( '../' + page ) > > How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself? The main ways we handle something like this are: 1. Set an environment variable that Python then reads to get the DocumentRoot value. 2. Use something like zc.buildout to produce both your httpd.conf and create a config file containing the value of DocumentRoot.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web