Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36892 > unrolled thread

Forcing Python to detect DocumentRoot

Started byFerrous Cranus <nikos.gr33k@gmail.com>
First post2013-01-16 05:51 -0800
Last post2013-01-19 17:53 -0800
Articles 20 on this page of 35 — 11 participants

Back to article view | Back to comp.lang.python


Contents

  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 1 of 2  [1] 2  Next page →


#36892 — Forcing Python to detect DocumentRoot

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-16 05:51 -0800
SubjectForcing Python to detect DocumentRoot
Message-ID<339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com>
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?

[toc] | [next] | [standalone]


#36893

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-16 09:01 -0500
Message-ID<mailman.568.1358344869.2939.python-list@python.org>
In reply to#36892

[Multipart message — attachments visible in raw view] — view raw

On Wed, Jan 16, 2013 at 8:51 AM, 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?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I don't think I understand your question.  But, I think your answer is
here: http://docs.python.org/2/library/os.path.html

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#36895

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-16 06:32 -0800
Message-ID<b15fb1f1-1cdf-4fe3-8253-34ab3e3d856c@googlegroups.com>
In reply to#36893
Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε:
> On Wed, Jan 16, 2013 at 8:51 AM, 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?
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> I don't think I understand your question.  But, I think your answer is here: 

Nowhere that page says something about python detecting documentroot directory (www or public_html) that is.

[toc] | [prev] | [next] | [standalone]


#36896

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-16 09:39 -0500
Message-ID<mailman.570.1358347192.2939.python-list@python.org>
In reply to#36895

[Multipart message — attachments visible in raw view] — view raw

On Wed, Jan 16, 2013 at 9:32 AM, Ferrous Cranus <nikos.gr33k@gmail.com>wrote:

> Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel
> Goldstick έγραψε:
> > On Wed, Jan 16, 2013 at 8:51 AM, 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?
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> > I don't think I understand your question.  But, I think your answer is
> here:
>
> Nowhere that page says something about python detecting documentroot
> directory (www or public_html) that is.
>

What is DocumentRoot?  This is a convention, not something a language would
'know' about

> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#36898

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-16 06:32 -0800
Message-ID<mailman.572.1358347492.2939.python-list@python.org>
In reply to#36893
Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel Goldstick έγραψε:
> On Wed, Jan 16, 2013 at 8:51 AM, 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?
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> I don't think I understand your question.  But, I think your answer is here: 

Nowhere that page says something about python detecting documentroot directory (www or public_html) that is.

[toc] | [prev] | [next] | [standalone]


#36929

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-17 01:03 -0800
Message-ID<ab450fc5-4413-47f6-8e14-3aa36969f60a@googlegroups.com>
In reply to#36892
Document Root for me is /home/nikos/public_html
Is where Apache store the user www files.

How to tell it my using a variable? 

[toc] | [prev] | [next] | [standalone]


#36937

Fromrusi <rustompmody@gmail.com>
Date2013-01-17 05:51 -0800
Message-ID<ba1775e0-ccb1-4f1c-b076-5ab9cf472f67@j4g2000yqh.googlegroups.com>
In reply to#36892
On Jan 16, 6: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?

Is this what you want?
import os
os.getcwd()

[toc] | [prev] | [next] | [standalone]


#36939

FromRoy Smith <roy@panix.com>
Date2013-01-17 09:09 -0500
Message-ID<roy-E9765E.09090217012013@news.panix.com>
In reply to#36892
In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com>,
 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?

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?

[toc] | [prev] | [next] | [standalone]


#36942

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-17 10:14 -0500
Message-ID<mailman.590.1358435662.2939.python-list@python.org>
In reply to#36939

[Multipart message — attachments visible in raw view] — view raw

On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <roy@panix.com> wrote:

> In article <339d9d6d-b000-4cf3-8534-375e0c44b2ca@googlegroups.com>,
>  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?
>
> 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 .



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#36994

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-18 05:02 -0800
Message-ID<10ebf68d-12f9-46d6-be50-6c314500302d@googlegroups.com>
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]


#36997

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-18 08:28 -0500
Message-ID<mailman.628.1358515700.2939.python-list@python.org>
In reply to#36994

[Multipart message — attachments visible in raw view] — view raw

On Fri, Jan 18, 2013 at 8:02 AM, Ferrous Cranus <nikos.gr33k@gmail.com>wrote:

> Τη Πέμπτη, 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...
> --
> http://mail.python.org/mailman/listinfo/python-list
>


DocumentRoot = os.environ['HOME'] + 'public_html'
-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#37018

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-18 10:58 -0800
Message-ID<2bf766db-ffcd-4a7f-8e08-6e3400618e78@googlegroups.com>
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]


#37022

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-18 14:11 -0500
Message-ID<mailman.646.1358536713.2939.python-list@python.org>
In reply to#37018

[Multipart message — attachments visible in raw view] — view raw

On Fri, Jan 18, 2013 at 1:58 PM, Ferrous Cranus <nikos.gr33k@gmail.com>wrote:

> Τη Παρασκευή, 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?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

My website experience with python has been using mod wsgi (and django), not
cgi.  I can't help you with how to configure cgi, but googling python cgi
might help

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#37031

FromChris Angelico <rosuav@gmail.com>
Date2013-01-19 08:34 +1100
Message-ID<mailman.652.1358544847.2939.python-list@python.org>
In reply to#37018
On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> Τη Παρασκευή, 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?

Time to take a step backward and figure out what you're really trying
to accomplish. I think, after gazing idly into my crystal ball for a
while, that you actually want to chroot your script - instead of
seeing "/home/nikos/public_html/" it would see just "/", and then it
can't access anything outside of that.

ChrisA

[toc] | [prev] | [next] | [standalone]


#37065

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-19 00:01 -0800
Message-ID<ebe13670-42aa-4c3c-91da-a297a7b8e6e8@googlegroups.com>
In reply to#37031
Τη Παρασκευή, 18 Ιανουαρίου 2013 11:34:05 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
> On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> 
> > Τη Παρασκευή, 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?
> 
> 
> 
> Time to take a step backward and figure out what you're really trying
> 
> to accomplish. I think, after gazing idly into my crystal ball for a
> 
> while, that you actually want to chroot your script - instead of
> 
> seeing "/home/nikos/public_html/" it would see just "/", and then it
> 
> can't access anything outside of that.
> 
> 
> 
> ChrisA


This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root

========================================
    # render html template and print it
    data = f.read()
    counter = '''<center>
                 <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a>
                 
                 <table border=2 cellpadding=2 bgcolor=black>
                 <td><font color=lime> Αριθμός Επισκεπτών </td>
                 <td><font color=cyan> %d </td>''' % hits[0]
========================================

While from within the same counter.py file

# open html template file
    f = open( '/home/nikos/public_html/test.txt' )

opens OK the page file which is also past addons domain's document root

Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct?

[toc] | [prev] | [next] | [standalone]


#37219

FromMichael Torrie <torriem@gmail.com>
Date2013-01-21 11:49 -0700
Message-ID<mailman.760.1358794195.2939.python-list@python.org>
In reply to#37065
On 01/19/2013 01:01 AM, Ferrous Cranus wrote:
> # render html template and print it data = f.read() counter =
> '''<center> <a href="mailto:support@superhost.gr"> <img
> src="/data/images/mail.png"> </a>
> 
> <table border=2 cellpadding=2 bgcolor=black> <td><font color=lime>
> Αριθμός Επισκεπτών </td> <td><font color=cyan> %d </td>''' % hits[0] 
> ========================================
> 
> While from within the same counter.py file
> 
> # open html template file f = open(
> '/home/nikos/public_html/test.txt' )
> 
> opens OK the page file which is also past addons domain's document
> root
> 
> Can you help counter.py to load the image? Why does it fail to load
> it? Python can have access to ANY filesystempath , no matter from
> what folder counter.py script runs from. Correct?

No I can't because counter.py doesn't "load the image."  The browser
does.  If the image fails to load it is because the apache web server
cannot find it.  In other words your image src url is bad.  It has
nothing to do with python.  Python is only spitting out html code.
That's it.  Image loading is done by apache on behalf of a request from
the web browser.  Since the url is a direct url to a file, there is no
CGI that runs.

I understand that you have a difficulty understanding the relationship
between the browser, the web server, and the cgi script.  The process
goes like this:

- browser requests the url, which happens to be the CGI script, counter.py.
- web server runs counter.py returns html code to the browser.
- browser parses html code, renders it, and requests any images that the
html code references.
- Web server tries to locate the image based on its own rules and
config, and serves it if possible, otherwise, returns error 404.

So you simply have the image url wrong.  apache is not mapping /data to
where you think it is.  You have to either fix this in apache's configs,
or determine where the image really is in apache's url space, and change
the cgi to output the correct html.  Your problem isn't a python one at
all; it's an apache problem.

[toc] | [prev] | [next] | [standalone]


#37067

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-19 00:01 -0800
Message-ID<mailman.676.1358583157.2939.python-list@python.org>
In reply to#37031
Τη Παρασκευή, 18 Ιανουαρίου 2013 11:34:05 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
> On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> 
> > Τη Παρασκευή, 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?
> 
> 
> 
> Time to take a step backward and figure out what you're really trying
> 
> to accomplish. I think, after gazing idly into my crystal ball for a
> 
> while, that you actually want to chroot your script - instead of
> 
> seeing "/home/nikos/public_html/" it would see just "/", and then it
> 
> can't access anything outside of that.
> 
> 
> 
> ChrisA


This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root

========================================
    # render html template and print it
    data = f.read()
    counter = '''<center>
                 <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a>
                 
                 <table border=2 cellpadding=2 bgcolor=black>
                 <td><font color=lime> Αριθμός Επισκεπτών </td>
                 <td><font color=cyan> %d </td>''' % hits[0]
========================================

While from within the same counter.py file

# open html template file
    f = open( '/home/nikos/public_html/test.txt' )

opens OK the page file which is also past addons domain's document root

Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct?

[toc] | [prev] | [next] | [standalone]


#37096

FromPiet van Oostrum <piet@vanoostrum.org>
Date2013-01-19 21:01 +0100
Message-ID<m2y5fposc4.fsf@cochabamba.vanoostrum.org>
In reply to#37067
Ferrous Cranus <nikos.gr33k@gmail.com> writes:

> This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root
>
> ========================================
>     # render html template and print it
>     data = f.read()
>     counter = '''<center>
>                  <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a>
>                  
>                  <table border=2 cellpadding=2 bgcolor=black>
>                  <td><font color=lime> Αριθμός Επισκεπτών </td>
>                  <td><font color=cyan> %d </td>''' % hits[0]
> ========================================
>

> While from within the same counter.py file
>
> # open html template file
>     f = open( '/home/nikos/public_html/test.txt' )
>
> opens OK the page file which is also past addons domain's document root
>
> Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct?

That piece of code is not opening the image file. It just issues the URL
for the image file. The file will then be loaded by the browser in a new
request. The image should be at
/home/nikos/public_html/data/images/mail.png

P.S. I don't understand what you mean by "addon domain".

-- 
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

[toc] | [prev] | [next] | [standalone]


#37158

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-20 22:25 -0800
Message-ID<c435de79-a4bf-447a-b187-b6f8866be675@googlegroups.com>
In reply to#37096
Τη Σάββατο, 19 Ιανουαρίου 2013 10:01:15 μ.μ. UTC+2, ο χρήστης Piet van Oostrum έγραψε:
> Ferrous Cranus <nikos.gr33k@gmail.com> writes:
> 
> 
> 
> > This is addon domain's counter.py snippet tried to load an image mail.png and failed because it cant see past its document root
> 
> >
> 
> > ========================================
> 
> >     # render html template and print it
> 
> >     data = f.read()
> 
> >     counter = '''<center>
> 
> >                  <a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a>
> 
> >                  
> 
> >                  <table border=2 cellpadding=2 bgcolor=black>
> 
> >                  <td><font color=lime> Αριθμός Επισκεπτών </td>
> 
> >                  <td><font color=cyan> %d </td>''' % hits[0]
> 
> > ========================================
> 
> >
> 
> 
> 
> > While from within the same counter.py file
> 
> >
> 
> > # open html template file
> 
> >     f = open( '/home/nikos/public_html/test.txt' )
> 
> >
> 
> > opens OK the page file which is also past addons domain's document root
> 
> >
> 
> > Can you help counter.py to load the image? Why does it fail to load it? Python can have access to ANY filesystempath , no matter from what folder counter.py script runs from. Correct?
> 
> 
> 
> That piece of code is not opening the image file. It just issues the URL
> 
> for the image file. The file will then be loaded by the browser in a new
> 
> request. The image should be at
> 
> /home/nikos/public_html/data/images/mail.png

Yes the image is this and is located at that folder.

/home/nikos/public_html/cgi-bin/counter.py

that has embedded this line:

<a href="mailto:support@superhost.gr"> <img src="/data/images/mail.png"> </a>

can open the file normally as seen if you visit http://superhost.gr


> P.S. I don't understand what you mean by "addon domain".


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.

[toc] | [prev] | [next] | [standalone]


#37184

FromDave Angel <d@davea.name>
Date2013-01-21 07:33 -0500
Message-ID<mailman.741.1358771626.2939.python-list@python.org>
In reply to#37158
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

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web