Re: WSGI (was: Re: Python CGI)

2014-05-25 Thread alister
On Sun, 25 May 2014 09:06:18 +0200, Chris wrote:

> On 05/20/2014 03:52 AM, Tim Chase wrote:
>> While Burak addressed your (Fast-)CGI issues, once you have a
>> test-script successfully giving you output, you can use the
>> standard-library's getpass.getuser() function to tell who your script
>> is running as.
> 
> LoadModule wsgi_module modules/mod_wsgi.so AddHandler wsgi-script .wsgi
> WSGIDaemonProcess myproj user=chris threads=3
> 
> [root@t-centos1 ~]# ps -ef|grep chris chris 1201  1199  0 08:47 ?   
> 00:00:00 /usr/sbin/httpd
> 
> ---8<---
> #!/usr/bin/python import getpass def application(environ,
> start_response):
> status = '200 OK'
> output = 'Hello World!'
> output += getpass.getuser()
> response_headers = [('Content-type', 'text/plain'),
> ('Content-Length', str(len(output)))]
> start_response(status, response_headers)
> 
> return [output]
> --->8---
> 
> Hello World!root
> 
> Hmm, why is it root?
> 
> I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for
> each user?
> 
> - Chris

is your apache server running as root?
if so it probably should be corrected


-- 
Why is it taking so long for her to bring out all the good in you?
-- 
https://mail.python.org/mailman/listinfo/python-list


WSGI (was: Re: Python CGI)

2014-05-25 Thread Chris
On 05/20/2014 03:52 AM, Tim Chase wrote:
> While Burak addressed your (Fast-)CGI issues, once you have a
> test-script successfully giving you output, you can use the
> standard-library's getpass.getuser() function to tell who your script
> is running as.

LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi
WSGIDaemonProcess myproj user=chris threads=3

[root@t-centos1 ~]# ps -ef|grep chris
chris 1201  1199  0 08:47 ?00:00:00 /usr/sbin/httpd

---8<---
#!/usr/bin/python
import getpass
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
output += getpass.getuser()
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]
--->8---

Hello World!root

Hmm, why is it root?

I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for
each user?

- Chris

-- 
Gruß,
Christian
-- 
https://mail.python.org/mailman/listinfo/python-list


WSGI (was: Re: Python CGI)

2014-05-25 Thread Christian
On 05/20/2014 03:52 AM, Tim Chase wrote:
> While Burak addressed your (Fast-)CGI issues, once you have a
> test-script successfully giving you output, you can use the
> standard-library's getpass.getuser() function to tell who your script
> is running as.

LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi
WSGIDaemonProcess myproj user=chris threads=3

[root@t-centos1 ~]# ps -ef|grep chris
chris 1201  1199  0 08:47 ?00:00:00 /usr/sbin/httpd

---8<---
#!/usr/bin/python
import getpass
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
output += getpass.getuser()
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]
--->8---

Hello World!root

Hmm, why is it root?

I'm using Apache and mod_userdir. Can I define WSGIDaemonProcess for
each user?

- Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python CGI

2014-05-19 Thread Tim Chase
On 2014-05-19 20:32, Christian wrote:
> I'd like to use Python for CGI-Scripts. Is there a manual how to
> setup Python with Fast-CGI? I'd like to make sure that Python
> scripts aren't executed by www-user, but the user who wrote the
> script.

While Burak addressed your (Fast-)CGI issues, once you have a
test-script successfully giving you output, you can use the
standard-library's getpass.getuser() function to tell who your script
is running as.

-tkc


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python CGI

2014-05-19 Thread Burak Arslan

On 05/19/14 21:32, Christian wrote:
> Hi,
>
> I'd like to use Python for CGI-Scripts. Is there a manual how to setup
> Python with Fast-CGI?

Look for Mailman fastcgi guides.

Here's one for gentoo, but I imagine it'd be easily applicable to other
disros:
https://www.rfc1149.net/blog/2010/12/30/configuring-mailman-with-nginx-on-gentoo/

hth,
burak
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Python - CGI-BIN - Apache Timeout Problem

2012-03-04 Thread Sean Cavanaugh (scavanau)
Thanks Chris,

I isolated it using logging

import logging 
logging.basicConfig(filename="test3.log", level=logging.INFO)
then logging.info('sniffer got to point A')  

and going through my code until I isolated the problem to a function with scapy 
called sniff.  For some reason this function operates very weirdly on FreeBSD9. 
 I have already submitted an email to the scapy mailing list.  Going to try to 
replicate this on Fedora but I doubt I will see this problem.  Even from the 
command line the sniff() function is not working correctly on FreeBSD 9.

-S  

-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Friday, March 02, 2012 3:23 PM
To: Sean Cavanaugh (scavanau)
Cc: python-list@python.org
Subject: Re: Python - CGI-BIN - Apache Timeout Problem

On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau)
 wrote:

> THE PROBLEM:
>
> When I execute the scripts from the command line (#python main.py) it
> generates it fine (albeit slowly), it prints all the html code out including
> the script.  The ‘core’ part of the script dumbed down to the lowest level
> is->
>
>     proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'],
> stdout=subprocess.PIPE)
>     output = proc.stdout.read()

Note the red warning box about possible deadlock with .stdout.read()
and friends:
http://docs.python.org/library/subprocess.html#popen-objects

>     print output
>     proc.stdout.close()

As the docs advise, try using .communicate()
[http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
] instead:
proc = subprocess.Popen(…)
out, err = proc.communicate()
print out

> When I open main.py and execute the script it just hangs… it seems to
> execute the script (I see pcap fires on the interface that I am testing on
> the firewall) but its not executing correctly… or loading the entire
> webpage…the webpage keeps chugging along and eventually gives me an error
> timeout.

The hanging makes me suspect that the aforementioned deadlock is occurring.

Cheers,
Chris
--
http://chrisrebert.com
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python - CGI-BIN - Apache Timeout Problem

2012-03-02 Thread Sean Cavanaugh (scavanau)
Hey All,

So maybe this part is important (after doing some troubleshooting)  hopefully 
not everyone has beers in hand already since its Friday :-) 

The way the code works if you want to send through the firewall (i.e.   
SERVER->FIREWALL->SERVER)  I split the process into two threads.  One is 
listening on the egress, then I send on the ingress.  The main waits until the 
thread finishes (it times out after 2 seconds).  I had to do this b/c scapy 
(the library I used) won't let me send pcaps while I receive them.  This lets 
me see packets on both sides (i.e. did that sort of internet traffic go through 
the firewall).   The reason I think this could be a problem is when I ran a 
test where I sent to the firewall (rather than through it) and my program does 
not need to thread the webserver works fine..   

Suggestions anyone?

-S

-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Friday, March 02, 2012 3:23 PM
To: Sean Cavanaugh (scavanau)
Cc: python-list@python.org
Subject: Re: Python - CGI-BIN - Apache Timeout Problem

On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau)
 wrote:

> THE PROBLEM:
>
> When I execute the scripts from the command line (#python main.py) it
> generates it fine (albeit slowly), it prints all the html code out including
> the script.  The ‘core’ part of the script dumbed down to the lowest level
> is->
>
>     proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'],
> stdout=subprocess.PIPE)
>     output = proc.stdout.read()

Note the red warning box about possible deadlock with .stdout.read()
and friends:
http://docs.python.org/library/subprocess.html#popen-objects

>     print output
>     proc.stdout.close()

As the docs advise, try using .communicate()
[http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
] instead:
proc = subprocess.Popen(…)
out, err = proc.communicate()
print out

> When I open main.py and execute the script it just hangs… it seems to
> execute the script (I see pcap fires on the interface that I am testing on
> the firewall) but its not executing correctly… or loading the entire
> webpage…the webpage keeps chugging along and eventually gives me an error
> timeout.

The hanging makes me suspect that the aforementioned deadlock is occurring.

Cheers,
Chris
--
http://chrisrebert.com
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python - CGI-BIN - Apache Timeout Problem

2012-03-02 Thread Sean Cavanaugh (scavanau)
Hey Chris,

Thanks for your quick reply!  I switched my code to->

proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], 
stdout=subprocess.PIPE)
out, err = proc.communicate()
print out
proc.stdout.close()

It still dead locked.  Interestingly enough When I did a #python tests.py on 
the command line even that was taking awhile to print out to the command line 
so I decided to restart my webserver... wow from mucking before something must 
have been running in the background still.  I got the script down to 2 seconds 
or so... 

Now it still works but faster when I do #python main.py it generates all the 
text to the command line but the website still hangs when I go to 
http://webserver/main.py... I am not sure what is going wrong... no error in 
the /var/log except for the eventual timeout after a couple minutes goes by.

-S

-Original Message-
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Friday, March 02, 2012 3:23 PM
To: Sean Cavanaugh (scavanau)
Cc: python-list@python.org
Subject: Re: Python - CGI-BIN - Apache Timeout Problem

On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau)
 wrote:

> THE PROBLEM:
>
> When I execute the scripts from the command line (#python main.py) it
> generates it fine (albeit slowly), it prints all the html code out including
> the script.  The ‘core’ part of the script dumbed down to the lowest level
> is->
>
>     proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'],
> stdout=subprocess.PIPE)
>     output = proc.stdout.read()

Note the red warning box about possible deadlock with .stdout.read()
and friends:
http://docs.python.org/library/subprocess.html#popen-objects

>     print output
>     proc.stdout.close()

As the docs advise, try using .communicate()
[http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
] instead:
proc = subprocess.Popen(…)
out, err = proc.communicate()
print out

> When I open main.py and execute the script it just hangs… it seems to
> execute the script (I see pcap fires on the interface that I am testing on
> the firewall) but its not executing correctly… or loading the entire
> webpage…the webpage keeps chugging along and eventually gives me an error
> timeout.

The hanging makes me suspect that the aforementioned deadlock is occurring.

Cheers,
Chris
--
http://chrisrebert.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - CGI-BIN - Apache Timeout Problem

2012-03-02 Thread Chris Rebert
On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau)
 wrote:

> THE PROBLEM:
>
> When I execute the scripts from the command line (#python main.py) it
> generates it fine (albeit slowly), it prints all the html code out including
> the script.  The ‘core’ part of the script dumbed down to the lowest level
> is->
>
>     proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'],
> stdout=subprocess.PIPE)
>     output = proc.stdout.read()

Note the red warning box about possible deadlock with .stdout.read()
and friends:
http://docs.python.org/library/subprocess.html#popen-objects

>     print output
>     proc.stdout.close()

As the docs advise, try using .communicate()
[http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
] instead:
proc = subprocess.Popen(…)
out, err = proc.communicate()
print out

> When I open main.py and execute the script it just hangs… it seems to
> execute the script (I see pcap fires on the interface that I am testing on
> the firewall) but its not executing correctly… or loading the entire
> webpage…the webpage keeps chugging along and eventually gives me an error
> timeout.

The hanging makes me suspect that the aforementioned deadlock is occurring.

Cheers,
Chris
--
http://chrisrebert.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI windows

2010-08-13 Thread Thomas Jollans
On 2010-08-13 12:40, Srikanth N wrote:
> *2. How do i configure the Server?(If i use WAMP,XAMPP)
> *
Sorry, I forgot to link you to

http://www.editrocket.com/articles/python_apache_windows.html

Hope this helps.

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


Re: Python CGI windows

2010-08-13 Thread Thomas Jollans
On 2010-08-13 12:40, Srikanth N wrote:
> *1. How do we execute CGI Scripts in Windows?
> *
You'll need a web server.

> *2. How do i configure the Server?(If i use WAMP,XAMPP)
> *
For CGI, you just need your server configured for CGI, nothing
Python-specific. It would surprise me if XAMPP didn't set up a working
cgi-bin for your programming pleasure anyway.

> *3. Is mod_python required for python cgi?
> *
No. mod_python is a completely different approach to running Python from
the web. Don't use it, it's dead. If you want something similar, use
mod_wsgi.
**
Come to think of it, you should probably look into WSGI anyway -- you
can run WSGI scripts via CGI for the time being, that's simple enough,
and switch to something else for production, or for serious development,
later on.

> Someone Please revert back to me with the solution for the same.I
> would be at-most thankful
 
This line is fascinating,
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python, CGI and Sqlite3

2010-04-13 Thread Ahmed, Shakir
-Original Message-
From: python-list-bounces+shahmed=sfwmd@python.org
[mailto:python-list-bounces+shahmed=sfwmd@python.org] On Behalf Of
Tim Chase
Sent: Tuesday, April 13, 2010 2:36 PM
To: Majdi Sawalha
Cc: python-list@python.org
Subject: Re: Python, CGI and Sqlite3

On 04/13/2010 12:41 PM, Majdi Sawalha wrote:
> import sqlite3
>
> statement? and it gives the following error
> ImportError: No module named sqlite3,
>
> i tried it on python shell and all statements are work well.

A couple possible things are happening but here are a few that 
pop to mind:

1) you're running different versions of python (sqlite was 
bundled beginning in 2.5, IIRC) so when you run from a shell, you 
get python2.5+ but your CGI finds an older version.  Your CGI can 
dump the value of sys.version which you can compare with your 
shell's version

2) the $PYTHONPATH is different between the two.  Check the 
contents of sys.path in both the shell and the CGI program to see 
if they're the same.  You might also dump the results of 
os.environ.get('PYTHONPATH', None)  to see if an environment 
variable specifies the $PYTHONPATH differently

3) while it reads correctly above, it's theoretically possible 
that you have a spelling error like "import sqllite3"?  I've been 
stung once or twice by this sort of problem so it's not entirely 
impossible :)

-tkc

Tim is right, following import works fine with me.

import sqlite3 






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

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


Re: Python, CGI and Sqlite3

2010-04-13 Thread Tim Chase

On 04/13/2010 12:41 PM, Majdi Sawalha wrote:

import sqlite3

statement? and it gives the following error
ImportError: No module named sqlite3,

i tried it on python shell and all statements are work well.


A couple possible things are happening but here are a few that 
pop to mind:


1) you're running different versions of python (sqlite was 
bundled beginning in 2.5, IIRC) so when you run from a shell, you 
get python2.5+ but your CGI finds an older version.  Your CGI can 
dump the value of sys.version which you can compare with your 
shell's version


2) the $PYTHONPATH is different between the two.  Check the 
contents of sys.path in both the shell and the CGI program to see 
if they're the same.  You might also dump the results of 
os.environ.get('PYTHONPATH', None)  to see if an environment 
variable specifies the $PYTHONPATH differently


3) while it reads correctly above, it's theoretically possible 
that you have a spelling error like "import sqllite3"?  I've been 
stung once or twice by this sort of problem so it's not entirely 
impossible :)


-tkc







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


Re: Python CGI Upload from Server Status

2008-06-06 Thread Derek Tracy
On Fri, Jun 6, 2008 at 9:16 AM, John Dohn <[EMAIL PROTECTED]> wrote:

> On Sat, Jun 7, 2008 at 12:50 AM, Derek Tracy <[EMAIL PROTECTED]> wrote:
>
>> I am trying to create a simple python cgi app that allows the user to kick
>> off an ftp from the server the cgi is on to another server; I have that
>> piece working using ftplib but since the files in question are usually very
>> large (500mb to 2gb) in size I want to be able to display some sort of
>> status to the user, preferrably a progress bar of some sort.
>
>
> You'll need some AJAX progress bar (hint: google for this term ;-) that
> will be getting updates from the server or request an update every second or
> so.
>
> The question is if your upload code can provide progress tracking? If it's
> just a call to some xyz.upload("/here/is/my-500M-file.bin") that only
> returns after several minutes of uploading without giving you any updates on
> how fast things go you're probably out of luck.
> OTOH if it can do e.g.callbacks for progress reporting or if it can run in
> a separate thread that you could query somehow you can hook that to that
> AJAX thing of your choice.
>
> JDJ
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I will look for the AJAX Progress Bar, but I will admit I have never touched
AJAX and haven't written javascript in years.

I patched Pythons ftplib.py storbinary() to send callbacks to the specified
method, so I have the callbacks locked down.  The thing to note is that this
app isn't allowing the user to upload to the server the cgi is on but rather
allowing the user to kick off an ftp process on the server to another
server.

Would there be a way to do this with python cgi and automatically append or
update information on the page it is displaying?

-- 
-
Derek Tracy
[EMAIL PROTECTED]
-
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI Upload from Server Status

2008-06-06 Thread John Dohn
On Sat, Jun 7, 2008 at 12:50 AM, Derek Tracy <[EMAIL PROTECTED]> wrote:

> I am trying to create a simple python cgi app that allows the user to kick
> off an ftp from the server the cgi is on to another server; I have that
> piece working using ftplib but since the files in question are usually very
> large (500mb to 2gb) in size I want to be able to display some sort of
> status to the user, preferrably a progress bar of some sort.


You'll need some AJAX progress bar (hint: google for this term ;-) that will
be getting updates from the server or request an update every second or so.

The question is if your upload code can provide progress tracking? If it's
just a call to some xyz.upload("/here/is/my-500M-file.bin") that only
returns after several minutes of uploading without giving you any updates on
how fast things go you're probably out of luck.
OTOH if it can do e.g.callbacks for progress reporting or if it can run in a
separate thread that you could query somehow you can hook that to that AJAX
thing of your choice.

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

Re: Python - CGI - XML - XSD

2008-03-13 Thread Diez B. Roggisch
> Sorry, it was really late when i wrote this post. The file is an XSL
> file. It defines HTML depending on what appears in the XML document.

Then the content-type might be the culprit, yes. But testing so would have
been faster than waiting for answers here... 

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


Re: Python - CGI - XML - XSD

2008-03-12 Thread xkenneth
On Mar 12, 11:58 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> xkenneth wrote:
> > On Mar 12, 6:32 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> xkenneth wrote:
> >>> Hi All,
> >>>    Quick question. I've got an XML schema file (XSD) that I've
> >>> written, that works fine when my data is present as an XML file.
> >>> (Served out by apache2.) Now when I callpythonas a cgi script, and
> >>> tell it print out all of the same XML, also served up by apache2, the
> >>>XSDis not applied. Does this have to do with which content type i
> >>> defined when printing the xml to stdout?
> >> Who's applying the stylesheet? The browser, some application like XmlSpy or
> >> what?
>
> > The browser.
>
> Well, why should it validate your file? Browsers don't do that just for fun.
>
> Stefan

Sorry, it was really late when i wrote this post. The file is an XSL
file. It defines HTML depending on what appears in the XML document.

Regards,
Kenneth Miller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - CGI - XML - XSD

2008-03-12 Thread Stefan Behnel
xkenneth wrote:
> On Mar 12, 6:32 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> xkenneth wrote:
>>> Hi All,
>>>Quick question. I've got an XML schema file (XSD) that I've
>>> written, that works fine when my data is present as an XML file.
>>> (Served out by apache2.) Now when I call python as a cgi script, and
>>> tell it print out all of the same XML, also served up by apache2, the
>>> XSD is not applied. Does this have to do with which content type i
>>> defined when printing the xml to stdout?
>> Who's applying the stylesheet? The browser, some application like XmlSpy or
>> what?
> 
> The browser.

Well, why should it validate your file? Browsers don't do that just for fun.

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


Re: Python - CGI - XML - XSD

2008-03-12 Thread xkenneth
On Mar 12, 6:32 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> xkenneth wrote:
> > Hi All,
>
> >    Quick question. I've got an XML schema file (XSD) that I've
> > written, that works fine when my data is present as an XML file.
> > (Served out by apache2.) Now when I call python as a cgi script, and
> > tell it print out all of the same XML, also served up by apache2, the
> > XSD is not applied. Does this have to do with which content type i
> > defined when printing the xml to stdout?
>
> Who's applying the stylesheet? The browser, some application like XmlSpy or
> what?
>
> Diez

The browser.

Regards,
Kenneth Miller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - CGI - XML - XSD

2008-03-12 Thread Diez B. Roggisch
xkenneth wrote:

> Hi All,
> 
>Quick question. I've got an XML schema file (XSD) that I've
> written, that works fine when my data is present as an XML file.
> (Served out by apache2.) Now when I call python as a cgi script, and
> tell it print out all of the same XML, also served up by apache2, the
> XSD is not applied. Does this have to do with which content type i
> defined when printing the xml to stdout?

Who's applying the stylesheet? The browser, some application like XmlSpy or
what?

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


Re: Python CGI & Webpage with an Image

2008-03-08 Thread rodmc

> Is the cgi script in the same directory? The user's browser looks
> for the jpg relative to the URL it used to get the page, which in
> the case of the CGI script is the path to the script, not the
> path to the html file.


No the CGI script is in a different folder, I could move everything to
the same folder I guess.


> If server logs are hard to get or read, try my runcgi.py script:
>
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/550822

Thanks, I will try this.

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


Re: Python CGI & Webpage with an Image

2008-03-06 Thread Bryan Olson
rodmc wrote:
> [...] I have played around a bit more
> so that both the image and HTML file are in the public_html folder.
> They are called via python using a relative URL, and have permissions
> set to 755. Within the HTML file the image is accessed using just
> "banner.jpg". The actual page displays ok except for the image - so it
> has the same problem as before. However when the same page is
> displayed without running through a CGI it displays perfectly.

Is the cgi script in the same directory? The user's browser looks
for the jpg relative to the URL it used to get the page, which in
the case of the CGI script is the path to the script, not the
path to the html file.

If server logs are hard to get or read, try my runcgi.py script:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/550822


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


Re: Python CGI & Webpage with an Image

2008-03-06 Thread rodmc
Hi,

Thanks for your very quick response. I have played around a bit more
so that both the image and HTML file are in the public_html folder.
They are called via python using a relative URL, and have permissions
set to 755. Within the HTML file the image is accessed using just
"banner.jpg". The actual page displays ok except for the image - so it
has the same problem as before. However when the same page is
displayed without running through a CGI it displays perfectly.

Kind regards,

rod

On Mar 6, 11:46 am, Bryan Olson <[EMAIL PROTECTED]> wrote:
> rodmc wrote:
>
> [...]
>  > Python:
>  >
>  > f = open("finish.html")
>  > doc = f.read()
>  > f.close()
>  > print doc
>
> You might need to start with:
>
>  print "Content-Type: text/html"
>  print
>
> Is "finish.html" in the right place? When you browse to your
> script, can you see that you're getting the html?
>
>  > HTML:
> [...]
>  > 
> I suspect a server configuration and/or resource placement problem.
> The image has a relative URL, and the user's browser will look for
> it on the same path that it used to get the resource served by the
> cgi script, up to last '/'.
>
> Is banner.jpg in the right place, and is your web server configured
> to treat everything in that directory as a cgi script, and thus
> trying to execute the jpg?  If one of those is the problem, just
> move banner.jpg, and/or change the relative URL. For example,
> SRC="../banner.jpg" will cause the browser to look for the jpg
> one directory above.
>
> Failing that, can look at the web server's log?
>
> --
> --Bryan



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


Re: Python CGI & Webpage with an Image

2008-03-06 Thread Bryan Olson
rodmc wrote:
[...]
 > Python:
 >
 > f = open("finish.html")
 > doc = f.read()
 > f.close()
 > print doc

You might need to start with:

 print "Content-Type: text/html"
 print

Is "finish.html" in the right place? When you browse to your
script, can you see that you're getting the html?

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


Re: Python CGI & Webpage with an Image

2008-03-06 Thread rodmc
Hi,

Good point, some code samples is probably required. Please note that
for reasons of integration with another system I am not using a
templating system.


Anyway I have copied them below:

Python:

f = open("finish.html")
doc = f.read()
f.close()
print doc


HTML:










Thank you for uploading your file


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


Re: Python CGI & Webpage with an Image

2008-03-05 Thread Miki
Hello Rod,

> I have a set of CGI scripts set up and in one page (which is stored in
> an HTML file then printed via a python CGI) there is an image. However
> the image never displays, can anyone recommend a way round this
> problem?
We need more information, can you post a code snippet? error page? ...

My *guess* is that the web server don't know how to server the image
(wrong path configuration?)

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: Python CGI script and CSS style sheet

2008-01-23 Thread epsilon
Tim,

Thanks for the information and I'll work with you suggestions.  Also,
I will let you know what I find.

Thanks again,
Christopher


Tim Chase wrote:
> > I'm working with a Python CGI script that I am trying to use with an
> > external CSS (Cascading Style Sheet) and it is not reading it from the
> > web server.  The script runs fine minus the CSS formatting.  Does
> > anyone know if this will work within a Python CGI?  It seems that line
> > 18 is not being read properly.  One more thing.  I tested this style
> > sheet with pure html code (no python script) and everything works
> > great.
> >
> > Listed below is a modified example.
> >
> > ++
> >
> > 1#!/usr/bin/python
> > 2
> > 3import cgi
> > 4
> > 5print "Content-type: text/html\n"
>
> The answer is "it depends".  Mostly on the configuration of your
> web-server.  Assuming you're serving out of a cgi-bin/ directory,
> you'd be referencing
>
>http://example.com/cgi-bin/foo.py
>
> If your webserver (apache, lighttpd, whatever) has been
> configured for this directory to return contents of
> non-executable items, your above code will reference
>
>http://example.com/cgi-bin/central.css
>
> and so you may be able to just drop the CSS file in that directory.
>
> However, I'm fairly certain that Apache can be (and often is)
> configured to mark folders like this as "execute only, no
> file-reading".  If so, you'll likely get some sort of Denied
> message back if you fetch the CSS file via HTTP.
>
> A better way might be to reference the CSS file as
> "/media/central.css"
>
> 12  href="/media/central.css" />
>
> and then put it in a media folder which doesn't have the
> execute-only/no-read permission set.
>
> Another (less attractive) alternative is to have your CGI sniff
> the incoming request, so you can have both
>
>   http://example.com/cgi-bin/foo.py
>   http://example.com/cgi-bin/foo.py?file=css
>
> using the 'file' GET parameter to return the CSS file instead of
> your content.  I'd consider this ugly unless deploy-anywhere is
> needed, in which case it's not so bad because the deployment is
> just the one .py file (and optionally an external CSS file that
> it reads and dumps).
>
> -tkc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI script and CSS style sheet

2008-01-23 Thread Tim Chase
> I'm working with a Python CGI script that I am trying to use with an
> external CSS (Cascading Style Sheet) and it is not reading it from the
> web server.  The script runs fine minus the CSS formatting.  Does
> anyone know if this will work within a Python CGI?  It seems that line
> 18 is not being read properly.  One more thing.  I tested this style
> sheet with pure html code (no python script) and everything works
> great.
> 
> Listed below is a modified example.
> 
> ++
> 
> 1#!/usr/bin/python
> 2
> 3import cgi
> 4
> 5print "Content-type: text/html\n"

The answer is "it depends".  Mostly on the configuration of your 
web-server.  Assuming you're serving out of a cgi-bin/ directory, 
you'd be referencing

   http://example.com/cgi-bin/foo.py

If your webserver (apache, lighttpd, whatever) has been 
configured for this directory to return contents of 
non-executable items, your above code will reference

   http://example.com/cgi-bin/central.css

and so you may be able to just drop the CSS file in that directory.

However, I'm fairly certain that Apache can be (and often is) 
configured to mark folders like this as "execute only, no 
file-reading".  If so, you'll likely get some sort of Denied 
message back if you fetch the CSS file via HTTP.

A better way might be to reference the CSS file as 
"/media/central.css"

12 

and then put it in a media folder which doesn't have the 
execute-only/no-read permission set.

Another (less attractive) alternative is to have your CGI sniff 
the incoming request, so you can have both

  http://example.com/cgi-bin/foo.py
  http://example.com/cgi-bin/foo.py?file=css

using the 'file' GET parameter to return the CSS file instead of 
your content.  I'd consider this ugly unless deploy-anywhere is 
needed, in which case it's not so bad because the deployment is 
just the one .py file (and optionally an external CSS file that 
it reads and dumps).

-tkc





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


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread Justin Ezequiel
On Jan 3, 1:35 pm, jwwest <[EMAIL PROTECTED]> wrote:
> Thanks! That worked like an absolute charm.
>
> Just a question though. I'm curious as to why you have to use the
> msvcrt bit on Windows. If I were to port my app to *NIX, would I need
> to do anything similar?
>
> - James

not needed for *NIX as *NIX does not have a notion of binary- vs text-
mode

I seem to recall not needing the msvcrt stuff a while ago on Windows
but recently needed it again for Python CGI on IIS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread jwwest
On Jan 2, 8:56 pm, Justin Ezequiel <[EMAIL PROTECTED]>
wrote:
> On Jan 3, 7:50 am, jwwest <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all,
>
> > I'm working on a cgi script that zips up files and presents the zip
> > file to the user for download. It works fine except for the fact that
> > I have to overwrite the file using the same filename because I'm
> > unable to delete it after it's downloaded. The reason for this is
> > because after sending "Location: urlofzipfile" the script stops
> > processing and I can't call a file operation to delete the file. Thus
> > I constantly have a tmp.zip file which contains the previously
> > requested files.
>
> > Can anyone think of a way around this? Is there a better way to create
> > the zip file and present it for download "on-the-fly" than editing the
> > Location header? I thought about using Content-Type, but was unable to
> > think of a way to stream the file out.
>
> > Any help is appreciated, much thanks!
>
> > - James
>
> import sys, cgi, zipfile, os
> from StringIO import StringIO
>
> try: # Windows only
> import msvcrt
> msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
> except ImportError: pass
>
> HEADERS = '\r\n'.join(
> [
> "Content-type: %s;",
> "Content-Disposition: attachment; filename=%s",
> "Content-Title: %s",
> "Content-Length: %i",
> "\r\n", # empty line to end headers
> ]
> )
>
> if __name__ == '__main__':
> os.chdir(r'C:\Documents and Settings\Justin Ezequiel\Desktop')
> files = [
> '4412_ADS_or_SQL_Server.pdf',
> 'Script1.py',
> 'html_files.zip',
> 'New2.html',
> ]
> b = StringIO()
> z = zipfile.ZipFile(b, 'w', zipfile.ZIP_DEFLATED)
> for n in files:
> z.write(n, n)
>
> z.close()
>
> length = b.tell()
> b.seek(0)
> sys.stdout.write(
> HEADERS % ('application/zip', 'test.zip', 'test.zip', length)
> )
> sys.stdout.write(b.read())
> b.close()

Thanks! That worked like an absolute charm.

Just a question though. I'm curious as to why you have to use the
msvcrt bit on Windows. If I were to port my app to *NIX, would I need
to do anything similar?

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


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread Justin Ezequiel
On Jan 3, 7:50 am, jwwest <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm working on a cgi script that zips up files and presents the zip
> file to the user for download. It works fine except for the fact that
> I have to overwrite the file using the same filename because I'm
> unable to delete it after it's downloaded. The reason for this is
> because after sending "Location: urlofzipfile" the script stops
> processing and I can't call a file operation to delete the file. Thus
> I constantly have a tmp.zip file which contains the previously
> requested files.
>
> Can anyone think of a way around this? Is there a better way to create
> the zip file and present it for download "on-the-fly" than editing the
> Location header? I thought about using Content-Type, but was unable to
> think of a way to stream the file out.
>
> Any help is appreciated, much thanks!
>
> - James

import sys, cgi, zipfile, os
from StringIO import StringIO

try: # Windows only
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
except ImportError: pass

HEADERS = '\r\n'.join(
[
"Content-type: %s;",
"Content-Disposition: attachment; filename=%s",
"Content-Title: %s",
"Content-Length: %i",
"\r\n", # empty line to end headers
]
)

if __name__ == '__main__':
os.chdir(r'C:\Documents and Settings\Justin Ezequiel\Desktop')
files = [
'4412_ADS_or_SQL_Server.pdf',
'Script1.py',
'html_files.zip',
'New2.html',
]
b = StringIO()
z = zipfile.ZipFile(b, 'w', zipfile.ZIP_DEFLATED)
for n in files:
z.write(n, n)

z.close()

length = b.tell()
b.seek(0)
sys.stdout.write(
HEADERS % ('application/zip', 'test.zip', 'test.zip', length)
)
sys.stdout.write(b.read())
b.close()

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


Re: Python CGI and Browser timeout

2007-04-28 Thread Steve Holden
Steve Holden wrote:
> Sebastian Bassi wrote:
>> On 26 Apr 2007 14:48:29 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>> In order to work around this problem, I started printing empty strings
>>> (i.e. print "") so that the browser does not timeout.
>> How do you print something while doing the query and waiting for the results?
>> I saw some pages that display something like: "This page will be
>> updated in X seconds to show the results" (X is an estimated time
>> depending of server load), after a JS countdown, it refresh itself and
>> show the result or another "This page will be updated in X seconds to
>> show the results".
> 
> The usual way is by "client pull": send the content you want the user to 
> see, and include a Refresh: header - the easiest way is to include a 
> META tag in the html content  section like
> 
>
> 
> So the page can continually check whether the user's job is finished, if 
> it isn't just sending out the same content and then when it is printing 
> the details.
> 
I should have pointed out that N is the number of seconds to wait before 
refreshing.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get Python in your .sig and on the web. Blog and lens
holdenweb.blogspot.comsquidoo.com/pythonology
tag items:del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Python CGI and Browser timeout

2007-04-28 Thread Steve Holden
Sebastian Bassi wrote:
> On 26 Apr 2007 14:48:29 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> In order to work around this problem, I started printing empty strings
>> (i.e. print "") so that the browser does not timeout.
> 
> How do you print something while doing the query and waiting for the results?
> I saw some pages that display something like: "This page will be
> updated in X seconds to show the results" (X is an estimated time
> depending of server load), after a JS countdown, it refresh itself and
> show the result or another "This page will be updated in X seconds to
> show the results".

The usual way is by "client pull": send the content you want the user to 
see, and include a Refresh: header - the easiest way is to include a 
META tag in the html content  section like

   

So the page can continually check whether the user's job is finished, if 
it isn't just sending out the same content and then when it is printing 
the details.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get Python in your .sig and on the web. Blog and lens
holdenweb.blogspot.comsquidoo.com/pythonology
tag items:del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Python CGI and Browser timeout

2007-04-26 Thread skulka3
Thanks for the response.

To further clarify the details:

I am printing the empty strings in a for loop. So the processing
happens in a loop when all the results from the query have been
already retrieved and each record is now being processed inside the
loop.

I also update the display periodically with the total number of
records processed(which is approximately after every 1/5th chunk of
the total number of records in the result).

Thanks,
Salil Kulkarni



On Apr 26, 6:01 pm, "Sebastian Bassi" <[EMAIL PROTECTED]>
wrote:
> On 26 Apr 2007 14:48:29 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > In order to work around this problem, I started printing empty strings
> > (i.e. print "") so that the browser does not timeout.
>
> How do you print something while doing the query and waiting for the results?
> I saw some pages that display something like: "This page will be
> updated in X seconds to show the results" (X is an estimated time
> depending of server load), after a JS countdown, it refresh itself and
> show the result or another "This page will be updated in X seconds to
> show the results".
>
> --
> Sebastián Bassi (セバスティアン)
> Diplomado en Ciencia y Tecnología.
> GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
> Club de la razón (www.clubdelarazon.org)


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

Re: Python CGI and Browser timeout

2007-04-26 Thread Sebastian Bassi
On 26 Apr 2007 14:48:29 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Is there a better solution to avoid browser timeouts?

Raising timeout in Apache, by default is 300 seconds.
Limiting jobs size (both in the html form and from script size since
you should not trust on client validations).

-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Club de la razón (www.clubdelarazon.org)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI and Browser timeout

2007-04-26 Thread Sebastian Bassi
On 26 Apr 2007 14:48:29 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> In order to work around this problem, I started printing empty strings
> (i.e. print "") so that the browser does not timeout.

How do you print something while doing the query and waiting for the results?
I saw some pages that display something like: "This page will be
updated in X seconds to show the results" (X is an estimated time
depending of server load), after a JS countdown, it refresh itself and
show the result or another "This page will be updated in X seconds to
show the results".



-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Club de la razón (www.clubdelarazon.org)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI and Browser timeout

2007-04-26 Thread Gabriel Genellina
En Thu, 26 Apr 2007 18:48:29 -0300, <[EMAIL PROTECTED]> escribió:

> I am creating a simple cgi script which needs to retrieve and process
> a huge number of records from the database (more than 11,000) and
> write the results to a file on disk  and display some results when
> processing is complete.
>
> However, nothing needs to be displayed while the processing is on. I
> was facing browser timeout issue due to the time it takes to process
> these records.
>
> In order to work around this problem, I started printing empty strings
> (i.e. print "") so that the browser does not timeout.
>
> Is there a better solution to avoid browser timeouts?

You could spawn another process or thread, reporting the progress  
somewhere.
Then redirect to another page showing the progress (and auto-reloading  
itself each few seconds).
When it detects that processing is complete, redirect to another page  
showing the final results.

-- 
Gabriel Genellina
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cgi problem with textarea

2007-04-24 Thread Adrian Smith
On Apr 24, 8:00 pm, placid <[EMAIL PROTECTED]> wrote:

> oops...i did read the problem description, but i when i tried the code
> it worked for me and when i put spaces into the TextArea it wasn't
> reflected correctly back. So i thought this was the problem.
>
> Adrian, can you still try replacing spaces with   via the
> following;
>
> #!/usr/bin/python
> import cgi
> import urllib
> import cgitb
> cgitb.enable()
> print "Content-type: text/html\n"
> form = cgi.FieldStorage()
> #print urllib.quote_plus(form["essay"].value)
>
> for char in form["essay"].value:
>if char == ' ':
>   print " "
>else:
>   print char
>
> Cheers

I'll try it...but I think it may be a problem on the server end. It's
not showing up in the server logs, either.

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


Re: python cgi problem with textarea

2007-04-24 Thread placid
On Apr 24, 4:52 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
> placid <[EMAIL PROTECTED]> wrote:
> >On Apr 23, 1:01 am, Adrian Smith <[EMAIL PROTECTED]> wrote:
> >> On Apr 22, 10:09 pm, placid <[EMAIL PROTECTED]> wrote:
>
> >> > i just tried it and its working. here it is
>
> >> >http://yallara.cs.rmit.edu.au/~bevcimen/form.html
>
> >> > maybe the internal server error is because mod_python isn't installed
> >> > assuming your using Apache as your web server
>
> >> Yeah, but it wouldn't work *at all* in that case, would it? ATM it
> >> seems to work as long as the textarea input has no spaces.
>
> >it doest work because the "space" character isnt interpreted
> >correctly, you need to change the space characters too  
>
> What???  Did you even read the problem description?

oops...i did read the problem description, but i when i tried the code
it worked for me and when i put spaces into the TextArea it wasn't
reflected correctly back. So i thought this was the problem.

Adrian, can you still try replacing spaces with   via the
following;

#!/usr/bin/python
import cgi
import urllib
import cgitb
cgitb.enable()
print "Content-type: text/html\n"
form = cgi.FieldStorage()
#print urllib.quote_plus(form["essay"].value)

for char in form["essay"].value:
   if char == ' ':
  print " "
   else:
  print char


Cheers

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


Re: python cgi problem with textarea

2007-04-23 Thread Tim Roberts
placid <[EMAIL PROTECTED]> wrote:
>On Apr 23, 1:01 am, Adrian Smith <[EMAIL PROTECTED]> wrote:
>> On Apr 22, 10:09 pm, placid <[EMAIL PROTECTED]> wrote:
>>
>> > i just tried it and its working. here it is
>>
>> >http://yallara.cs.rmit.edu.au/~bevcimen/form.html
>>
>> > maybe the internal server error is because mod_python isn't installed
>> > assuming your using Apache as your web server
>>
>> Yeah, but it wouldn't work *at all* in that case, would it? ATM it
>> seems to work as long as the textarea input has no spaces.
>
>it doest work because the "space" character isnt interpreted
>correctly, you need to change the space characters too  

What???  Did you even read the problem description?
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cgi problem with textarea

2007-04-23 Thread Peter Otten
Adrian Smith wrote:

> ...and I get an internal server error if I have any spaces in the
> textarea, which is really going to limit its usefulness to me. Oddly,

While debugging you should put

> #!/usr/bin/python
  
  import cgitb
  cgitb.enable()

> import cgi
> print "Content-type: text/html\n"
> form = cgi.FieldStorage()
> print form["essay"].value

at the beginning of your cgi -- just in case the error is in the python
script.

Peter

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


Re: python cgi problem with textarea

2007-04-23 Thread placid
On Apr 23, 1:01 am, Adrian Smith <[EMAIL PROTECTED]> wrote:
> On Apr 22, 10:09 pm, placid <[EMAIL PROTECTED]> wrote:
>
> > i just tried it and its working. here it is
>
> >http://yallara.cs.rmit.edu.au/~bevcimen/form.html
>
> > maybe the internal server error is because mod_python isn't installed
> > assuming your using Apache as your web server
>
> Yeah, but it wouldn't work *at all* in that case, would it? ATM it
> seems to work as long as the textarea input has no spaces.

it doest work because the "space" character isnt interpreted
correctly, you need
to change the space characters too  

Cheers


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


Re: python cgi problem with textarea

2007-04-22 Thread Graham Dumpleton
On Apr 22, 11:09 pm, placid <[EMAIL PROTECTED]> wrote:
> On Apr 22, 4:08 pm, Adrian Smith <[EMAIL PROTECTED]> wrote:
>
>
>
> > This may be more a cgi thing than a Python one, but I'm trying to get
> > this page:
>
> >http://adrian10.phpwebhosting.com/trial.html
>
> > consisting basically of this:
>
> > 
> > 
> > 
> > 
>
> > ...to print out the contents of the textarea with this cgi script:
>
> > #!/usr/bin/python
> > import cgi
> > print "Content-type: text/html\n"
> > form = cgi.FieldStorage()
> > print form["essay"].value
>
> > ...and I get an internal server error if I have any spaces in the
> > textarea, which is really going to limit its usefulness to me. Oddly,
> > it seems to work for a friend in the UK who's looked at it, but it
> > doesn't work for me here in Japan.
>
> i just tried it and its working. here it is
>
> http://yallara.cs.rmit.edu.au/~bevcimen/form.html
>
> maybe the internal server error is because mod_python isn't installed
> assuming your using Apache as your web server

You do not need mod_python installed to be able to run CGI scripts,
thus has nothing to do with mod_python.

Graham

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


Re: python cgi problem with textarea

2007-04-22 Thread Adrian Smith
On Apr 22, 10:09 pm, placid <[EMAIL PROTECTED]> wrote:

> i just tried it and its working. here it is
>
> http://yallara.cs.rmit.edu.au/~bevcimen/form.html
>
> maybe the internal server error is because mod_python isn't installed
> assuming your using Apache as your web server

Yeah, but it wouldn't work *at all* in that case, would it? ATM it
seems to work as long as the textarea input has no spaces.

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


Re: python cgi problem with textarea

2007-04-22 Thread Jim
On Apr 22, 2:08 am, Adrian Smith <[EMAIL PROTECTED]> wrote:
> ...and I get an internal server error if I have any spaces in the
> textarea,
And what error appears in the server error log?

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


Re: python cgi problem with textarea

2007-04-22 Thread Adrian Smith
On Apr 22, 11:40 pm, Jim <[EMAIL PROTECTED]> wrote:
> On Apr 22, 2:08 am, Adrian Smith <[EMAIL PROTECTED]> wrote:> ...and I
> > get an internal server error if I have any spaces in the textarea,
>
> And what error appears in the server error log?

I've just asked my web provider why I don't appear to have a server
error log, as a matter of fact - I'll post it if and when they reply.

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


Re: python cgi problem with textarea

2007-04-22 Thread placid
On Apr 22, 4:08 pm, Adrian Smith <[EMAIL PROTECTED]> wrote:
> This may be more a cgi thing than a Python one, but I'm trying to get
> this page:
>
> http://adrian10.phpwebhosting.com/trial.html
>
> consisting basically of this:
>
> 
> 
> 
> 
>
> ...to print out the contents of the textarea with this cgi script:
>
> #!/usr/bin/python
> import cgi
> print "Content-type: text/html\n"
> form = cgi.FieldStorage()
> print form["essay"].value
>
> ...and I get an internal server error if I have any spaces in the
> textarea, which is really going to limit its usefulness to me. Oddly,
> it seems to work for a friend in the UK who's looked at it, but it
> doesn't work for me here in Japan.

i just tried it and its working. here it is

http://yallara.cs.rmit.edu.au/~bevcimen/form.html

maybe the internal server error is because mod_python isn't installed
assuming your using Apache as your web server

Cheers


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


Re: Python cgi Apache os.system()

2006-11-09 Thread naima . mans
Hello

thanks for your help..

it was a problem of path as you mentionned... my command was "O:\\
ccm start" and i have change it with the path of the drive O

thanks a lot
 have a good day

Tachi

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


Re: Python cgi Apache os.system()

2006-11-08 Thread Cameron Walsh
[EMAIL PROTECTED] wrote:
> Hello :)
> 
> I have installed Apache on windows...
> The server work well, and my python script also
> 
> but when I want in my python script to run a System command like
> os.system(my_command) the script doesn't do anything!
> 
> here the error.log
> 
> [Wed Nov 08 14:19:30 2006] [error] [client 127.0.0.1] The system cannot
> find the drive specified.\r, referer:
> http://127.0.0.1/cgi-bin/extract_source.py
> 
> When i run the python script manually it works!
> 
> i think it's a user access probleme but i don't know how to resolve it
> !
> 
> please help  
> thanks
> 

Without knowing what "my_command" is, all I can suggest is that
"my_command" might be referring to a file that is in your user path, but
not in the path of the user used to run apache or python (which could be
"nobody").

Depending on how securely your server is configured, you may be able to
access whichever file it is looking for if you specify the full path to
the file, or the relative path from the server root directory (watch out
for hardlinks/softlinks.)

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


Re: Python CGI Scripting Documentation

2006-07-03 Thread per9000
Hi,

I wanted to try this myself a few days ago, my first (working) try had
this source code:

---
#!/usr/bin/python

print 'Content-Type: text/plain'
print
print 'hell o world'
---
(the output is just "hell o world\n", but the first four lines are
still required I guess, I don't know why, but it works...)

The file had to be named filetitle + ".cgi" because of some setting at
my web hotel. 

Good luck!

/Per9000

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


Re: Python CGI Scripting Documentation

2006-07-03 Thread Vlad Dogaru
Alex Martelli wrote:


Wow, I'm new in the field, but even I know your name. It's truly
inspiring to be aswered to by you. Thank you, all of you, for your
suggestions. I will try to look into the matter using the starting
points you've given me, as well as read more about Django.

Thanks,
Vlad.

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


Re: Python CGI Scripting Documentation

2006-07-02 Thread Alex Martelli
Vlad Dogaru <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> I would like to learn web scripting with Python (sure, everyone uses
> PHP, but I don't like the syntax and Python is more general-purpose
> and... well, I guess you people know the advantages better than me).
> Where can I get a thorough introduction to both CGI and using Python
> for CGI? That includes installing my own web server (at home, for
> testing) and starting from scratch (by that I mean I have near null
> experience with CGI).
> 
> I have tried looking through the source code of MoinMoin, but it's just
> too advanced for me -- I simply don't know where to start. Right now,
> I'll take any and all suggestions. However, please suggest books or
> articles that are up-to-date on Python programming; I'd hate to see
> that I'm studying obsolete texts or the like.

In terms of learning, Steve Holden's "Python Web Programming" is still
unbeatable -- it teaches you just enough of the many underlying
technologies, from HTTP to HTML to relational databases, as well as
Python.  However, it IS an old version of Python (sigh).  But it's very
easy to learn the relatively small enhancements to the Python language
since the time Steve penned his masterpiece... anything that used to
work then still works now, you have better ways to perform many tasks
(particularly thanks to additions to the standard library, and third
party extension modules matured in the meantime) but those are easy to
learn "afterwards" (and meanwhile, a solid understanding of the basics
of, say, HTTP and entity-relation design, will stand you in good stead
for years and years to come!-).  Steve's book is really the best you can
get, for "learning" purposes such as yours.  However...L

If you insist on getting coverage of the latest and greatest version of
Python, you might want to get the 2nd edition of my "Python in a
Nutshell", due out later this month; it strives to cover Python 2.5
(also due out later this month;-) as well as 2.4 (the still-now current
version, on which the new Nutshel focuses), and does have a chapter
specifically on CGI (not much changed from the first edition's, of
course, since CGI itself has not changed much over the years;-).

To have a look at my book (and just about any other O'Reilly book... and
not just O'Reilly either!) for free, subscribe to O'Reilly's "Safari"
online library -- I believe the first two weeks are free, so, as long as
you cancel in time, you should not have to pay a penny for the
privilege; thus, it may be a good idea (I personally like having access
to said library for searches etc, but that's a separate issue).  It will
be a while before the 2nd edition gets online -- but as I said the CGI
part is basically unchanged anyway.

But, talking of web resources...:

A Google search for Python CGI gives you 20 million hits, and quite a
few of those appear to be good tutorials on the subject -- why don't you
give those a try, first?  Sure, most of the pages will be using older
versions of Python -- but most of the differences should be of little
importance. One crucial one: you *DO* want to use the cgitb auxiliary
module to get good tracebacks in case of errors, and older sites may not
mention it -- however, that's pretty simple indeed...:

  import cgitb; cgitb.enable()

just place this line at the very top of your CGI script (after the
"shebang" line and the docstring, heh:-) and you're all set.  Any
further info you need for "advanced" usage of cgitb is in one tiny page
at .


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


Re: Python CGI Scripting Documentation

2006-07-02 Thread Michael
Sybren Stuvel wrote:

> Why use CGI when you can use a framework that's so much easier and
> more powerful?

Lots of possible answers, a few:
   * Fun
   * Transferable skills
   * No single solution is ever the answer to all problems
 (not all problems are nails, not all solutions are hammers)
   * Someone needs to understand the nuts and bolts of what's going on
   * Just because something is difficult doesn't mean its not worth doing
   * Understanding what's actually going on

But the killer answer for me really is: "Why not" :-)

Have fun :-)


Michael.

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


Re: Python CGI Scripting Documentation

2006-07-02 Thread placid

Vlad Dogaru wrote:
> Hello,
>
> I would like to learn web scripting with Python (sure, everyone uses
> PHP, but I don't like the syntax and Python is more general-purpose
> and... well, I guess you people know the advantages better than me).
> Where can I get a thorough introduction to both CGI and using Python
> for CGI? That includes installing my own web server (at home, for
> testing) and starting from scratch (by that I mean I have near null
> experience with CGI).
>
> I have tried looking through the source code of MoinMoin, but it's just
> too advanced for me -- I simply don't know where to start. Right now,
> I'll take any and all suggestions. However, please suggest books or
> articles that are up-to-date on Python programming; I'd hate to see
> that I'm studying obsolete texts or the like.

Chapter 12 of Programming Python 2nd Edition by Mark Lutz

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


Re: Python CGI problem: correct result, but incorrect browser response.

2006-04-06 Thread Tim Roberts
"Sullivan WxPyQtKinter" <[EMAIL PROTECTED]> wrote:
>
>title:Python CGI problem: correct result, but incorrect browser
>response.
>
>In one of my CGI program,named 'login.py', the script return a HEADER
>to web browser:
>
>Set-Cookie: sessionID=LAABUQLUCZIQJTZDWTFE;
>Set-Cookie: username=testuser;
>Status:302
>Location:edit.py
>(blank line)
>
>but the IE prompted to let me choose to save the 'login.py'. When I
>save it, the file is just the header. That means the IE failed to parse
>the header. My IE has already enabled cookie read and write. I also
>tried Firefox, but the result is the same. How does this happen?

Perhaps you should show us the script.  Is it possible that you have
already printed a "Content-Type" header and blank line before these
headers, or perhaps just a blank line?  Remember that this will fail:

print """
Set-Cookie: sessionID=LAABUQLUCZIQJTZDWTFE;
Set-Cookie: username=testuser;
Status:302
Location:edit.py
"""

because you get a blank line first, which terminates the headers.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cgi permision error

2006-03-19 Thread [EMAIL PROTECTED]
Sorry accidently replying using my other google account

[EMAIL PROTECTED] wrote:
> >
> > assuming you are running this python script the standard cgi way and not
> > through modpython or fastcgi.
> yes I'm running it in standard cgi way coz my provider only allow me
> that way.
And it's really just simple script. Sorry for the dumb question, I know
modpython but what do you mean by fast cgi
>
> >
> > try debugging this way.
> >
> > execute the python script from command line as the web user.
> >
> > make sure your python script prints the standard
> >
> > """Content-type: text/html
> >
> > """
>
Yess I've done that. I have also run it on windows machine and it work.
It seem my apache from SuSE 10.0 had some weird error permision that I
don't understand when running cgi. I'm also had that kinda error if I
running other cgi on perl or binary cgi :(

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


Re: python cgi permision error

2006-03-17 Thread devilandme
>
> assuming you are running this python script the standard cgi way and not
> through modpython or fastcgi.
yes I'm running it in standard cgi way coz my provider only allow me
that way.
And it's really just simple script. Sorry for the dumb question, I know
modpython but what do you mean by fast cgi

>
> try debugging this way.
>
> execute the python script from command line as the web user.
>
> make sure your python script prints the standard
>
> """Content-type: text/html
>
> """

Yess I've done that. I have also run it on windows machine and it work.
It seem my apache from SuSE 10.0 had some weird error permision that I
don't understand when running cgi. I'm also had that kinda error if I
running other cgi on perl or binary cgi :(

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


Re: python cgi permision error

2006-03-17 Thread David Bear
[EMAIL PROTECTED] wrote:

> Hi
> 
> I have python cgi script, but when I call it I got server internal
> error. The log in my apache is
> 
> [Sat Mar 18 04:17:14 2006] [error] [client 127.0.0.1] (13)Permission
> denied: exec of '/srv/www/cgi-bin/helo.cgi' failed
> [Sat Mar 18 04:17:14 2006] [error] [client 127.0.0.1] Premature end of
> script headers: helo.cgi
> [Sat Mar 18 04:20:09 2006] [notice] caught SIGTERM, shutting down
> 
> I have set the correct permision for the script(755) and the script is
> also own by apache uid.

assuming you are running this python script the standard cgi way and not
through modpython or fastcgi.

try debugging this way.

execute the python script from command line as the web user. 

make sure your python script prints the standard 

"""Content-type: text/html

"""

header.

> I think somehow apache cannot run python to process my python cgi
> script, but I don't know what I should do anymore.
> When I run it via shell, the cgi work fine
> I also can't make my mod_python .py write anything inside my /var/www
> dir although permision already true, even if I gave /var/www permision
> recursively to 777(I know this not good idea, just for testing), still
> have permision denied stuff.
> Btw I'm using SuSE 10, Apache/2.0.54, and python 2.4
> Sighhh, there's a lot of weird thing with my apache and I can't
> understand why :'(

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Kent Johnson
Harlin Seritt wrote:
> Also, is there a redirect command somewhere within Python CGI that can
> get this done instead as I would actually prefer to have the CGI code
> execute this rather than depend on the HTML to do it.

http://groups.google.com/group/comp.lang.python/msg/6e929fab0d414b2c 
shows how do do a redirect with HTTP headers.

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


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Iain King

Iain King wrote:
> Harlin Seritt wrote:
> > I have this Python CGI script running:
> >
> > [CODE]
> > print 'Content-type: text/plain\n'
> >
> > location = 'http://server1.com'
> >
> > page = '''
> > 
> > 
> > 
> > 
> > 
> > '''
> >
> > print page
> > [/CODE]
> >
> > It works fine and redirects perfectly when using Internet Explorer but
> > only shows this in a Firefox window:
> >
> > [OUTPUT]
> > 
> > 
> > http://server1.com";>
> > 
> > 
> > [/OUTPUT]
> >
> > Is there anything I can do to fix this?
> >
> > Also, is there a redirect command somewhere within Python CGI that can
> > get this done instead as I would actually prefer to have the CGI code
> > execute this rather than depend on the HTML to do it.
> >
> > Thanks,
> >
> > Harlin Seritt
>
> this snippet works (from code I wrote to implement a shoutbox):
>
> print '''
> 
>   
> 
> 
> Please wait...
> 
> '''
>
> I assume your version doesn't work because of the uppercase 'R'.
> 
> Iain

There's a well known phrase about the word 'assume'...

Iain

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


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Harlin Seritt
Ack... I'm an idiot... Thanks Richard -- You're the Man!

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


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Iain King

Harlin Seritt wrote:
> I have this Python CGI script running:
>
> [CODE]
> print 'Content-type: text/plain\n'
>
> location = 'http://server1.com'
>
> page = '''
> 
> 
> 
> 
> 
> '''
>
> print page
> [/CODE]
>
> It works fine and redirects perfectly when using Internet Explorer but
> only shows this in a Firefox window:
>
> [OUTPUT]
> 
> 
> http://server1.com";>
> 
> 
> [/OUTPUT]
>
> Is there anything I can do to fix this?
>
> Also, is there a redirect command somewhere within Python CGI that can
> get this done instead as I would actually prefer to have the CGI code
> execute this rather than depend on the HTML to do it.
>
> Thanks,
>
> Harlin Seritt

this snippet works (from code I wrote to implement a shoutbox):

print '''




Please wait...

'''

I assume your version doesn't work because of the uppercase 'R'.

Iain

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


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Richard Brodie

"Harlin Seritt" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> [CODE]
> print 'Content-type: text/plain\n'

That's your problem. You've said text/plain when you meant text/html.



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


Re: Python CGI

2005-12-01 Thread jbrewer
Thanks guys.  I didn't realize that hidden form fields were so easy to
use.

Jeremy

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


Re: Python CGI

2005-12-01 Thread BJ Swope
Here's a snippet of code I use in a CGI I use...

I check to see if the params has any data, if it does then return that
data and some other data that comes from the params.  If params is
empty, then draw a different page that says give me some data.

    if len(params):
    return params,inc_fields
    else:
    generate_form()
    sys.exit(1)


def generate_form():
    html_stuff.print_headers('Error','FF')
    print "Need some information for which to search...\n\n\n"
    html_stuff.form_open('search.cgi')
    html_stuff.submit_button('Try Again')
    print ''
    html_stuff.form_close()
    html_stuff.print_footers()
On 30 Nov 2005 20:52:01 -0800, jbrewer <[EMAIL PROTECTED]> wrote:
I need to update a CGI script I have been working on to performvalidation of input files.  The basic idea is this:1.) HTML page is served2.) User posts file and some other info3.) Check file for necessary data
* If data is missing, then post a 2nd page requesting needed data* If data is present, continue to 44.) Process input file and display results (processing path depends onwhether data from 3 was present in file or had to be input by user)
I'm unsure of the best way to implement step 3.  Is it even possible toput all of this into one script?  Or should I have one script check thefile for the data, then pass the info on to a 2nd script?  The
cgi.FieldStorage() function should only be called once, so it seemslike it's not possible to read a form and then repost another one andread it.  If this is true and I need 2 scripts, how do I pass on theinformation in step 3 automatically if the file has the proper data and
no user input is needed?Sorry if this is a dumb question (or unclear), but this is my(ever-growing) first CGI script.  Thanks.Jeremy--
http://mail.python.org/mailman/listinfo/python-list-- "But
we also know the dangers of a religion that severs its links with
reason and becomes prey to fundamentalism" --  Cardinal Paul
Poupard"It morphs into the Republican party!"  -- BJ
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI

2005-12-01 Thread Fuzzyman
That doesn't sound too difficult to do in a single script.

As Tim has mentioned, you can always separate the code in two modules
and just import the one needed for the action being performed.

Your script just needs to output different HTML depending on the result
- with a different form depending on what information is required.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Python CGI

2005-12-01 Thread Tim Roberts
"jbrewer" <[EMAIL PROTECTED]> wrote:
>
>I need to update a CGI script I have been working on to perform
>validation of input files.  The basic idea is this:
>
>1.) HTML page is served
>2.) User posts file and some other info
>3.) Check file for necessary data
>* If data is missing, then post a 2nd page requesting needed data
>* If data is present, continue to 4
>4.) Process input file and display results (processing path depends on
>whether data from 3 was present in file or had to be input by user)
>
>I'm unsure of the best way to implement step 3.  Is it even possible to
>put all of this into one script?  Or should I have one script check the
>file for the data, then pass the info on to a 2nd script?  The
>cgi.FieldStorage() function should only be called once, so it seems
>like it's not possible to read a form and then repost another one and
>read it.  If this is true and I need 2 scripts, how do I pass on the
>information in step 3 automatically if the file has the proper data and
>no user input is needed?

Each web transaction standsalone.  User sends request, you send reply, your
CGI process ends.  Every new request is another run.

So, you can either use one script per operation, or you can use one script
and detect which step it is using, for example a hidden field.

If you need common file processing in both scripts, I'm sure you already
know you can put that code in a separate Python file and import it into the
two CGI scripts.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI post problem

2005-11-24 Thread Paul Boddie
Eddy Ilg wrote:
> I'm having problems with a python cgi script. The script just won't read
> any POST data. Forms with GET data work fine.

[...]

> form=cgi.FieldStorage(keep_blank_values=True)

Since FieldStorage uses various defaults when you don't specify the fp
and environ parameters, it may be worth checking those defaults
(particularly what os.environ contains) to see if the FieldStorage
object gets incorrectly initialised. What you should be seeing in
os.environ is a value for "REQUEST_METHOD" of "POST" (or possibly
"post") - if not, FieldStorage will attempt to read the fields from the
QUERY_STRING environment variable, producing the results you've
observed.

Paul

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


Re: python CGI,sybase and environ variables

2005-11-02 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> hi
> i am writing a CGI to process some database transactions using the
> Sybase module.
> so in my CGI script, i have:
> 
> ...
> import Sybase
> import cgitb; cgitb.enable(display=1 , logdir="/tmp/weblog.txt")
> ...
> ...
> 
> the problem is , everytime i have ImportError: No module named Sybase
> flagged out.
> 
> at first i think it's library path misconfiguration, so i put
> os.environ["SYBASE"] = '/path/to/sybase'
> os.environ["LD_LIBRARY_PATH"] =  '/path/to/sybase/lib'
> 
> before i import Sybase. but its still the same error
> 
> Ok.so now, is it necesary to configure the web server's "nobody" user's
> profile to point to the Sybase libraries? or worse, configure root's
> profile to point to Sybase libraries? what's could be wrong?
> thanks for any help rendered.
> 
You should try adding "/path/to/sybase" to sys.path as well as/rather 
than putting it in an environment variable. sys.path is what the 
interpreter uses to find importable modules.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: python CGI,sybase and environ variables

2005-11-02 Thread eight02645999
i have solved the problem.
thanks.

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


RE: python cgi script not understood as html

2005-10-25 Thread Iyer, Prasad C

Your python script is not getting executed.
I guess there is something wrong with the server configuration.



#-Original Message-
#From: Philippe C. Martin [mailto:[EMAIL PROTECTED]
#Sent: Tuesday, October 25, 2005 1:27 AM
#To: python-list@python.org
#Subject: python cgi script not understood as html
#
#Hi,
#
#The following code outputs the actual HTML text to the browser, not the
#interpreted text.
#
#Any idea ?
#
#Regards,
#
#Philippe
#import cgi
#import logging
#import auth #this is the one you must implement (or use SCF ;-)
#
#html_ok = """
#Content-Type: text/html\n
#http://www.w3.org/TR/html4/loose.dtd";>\n
#\n
#\n
#  Access Granted\n
#  \n
#  \n
#\n
#\n
#Access Granted\n
#\n
#Welcome %s \n
#\n
#\n
#\n
#"""
#
#html_nok = """
#"Content-Type: text/html\n\n"
#http://www.w3.org/TR/html4/loose.dtd";>
#
#
#
#  Access Granted
#  
#  
#
#
#Access Denied
#
#
#
#
#
#"""
## DISPLAY ACCESS DENIED PAGE
#def Failure():
#print html_nok
#
##DISPLAY ACCESS GRANTED PAGE
#def Success(p_data):
#print html_ok % (p_data)


This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient,  you are not authorized 
to read, print, retain, copy, disseminate,  distribute, or use this message or 
any part thereof. If you receive this  message in error, please notify the 
sender immediately and delete all  copies of this message.

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


Re: python cgi script not understood as html

2005-10-24 Thread Philippe C. Martin
It is, thanks.

Philippe



Peter Hansen wrote:

> Philippe C. Martin wrote:
>> The following code outputs the actual HTML text to the browser, not the
>> interpreted text.
>> 
>> html_ok = """
>> Content-Type: text/html\n
>> > "http://www.w3.org/TR/html4/loose.dtd";>\n
> 
> HTTP header lines must end with \r\n, not just with \n.  Not sure this
> is the solution to your specific problem though...
> 
> -Peter

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


Re: python cgi script not understood as html

2005-10-24 Thread Philippe C. Martin
Many thanks !!

Regards,

Philippe



Mitja Trampus wrote:

> Philippe C. Martin wrote:
>> Hi,
>> 
>> The following code outputs the actual HTML text to the browser, not the
>> interpreted text.
>> 
>> Any idea ?
>> 
>> html_ok = """
>> Content-Type: text/html\n
>  > 
>  > ...
>  > """
> 
> Avoid the starting newline (before content-type).
> Add at least TWO newlines after content-type.
> 
> Or use a package to handle the HTTP stuff for you.

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


Re: python cgi script not understood as html

2005-10-24 Thread Peter Hansen
Philippe C. Martin wrote:
> The following code outputs the actual HTML text to the browser, not the
> interpreted text.
> 
> html_ok = """
> Content-Type: text/html\n
>  "http://www.w3.org/TR/html4/loose.dtd";>\n

HTTP header lines must end with \r\n, not just with \n.  Not sure this 
is the solution to your specific problem though...

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


Re: python cgi script not understood as html

2005-10-24 Thread Mitja Trampus
Philippe C. Martin wrote:
> Hi,
> 
> The following code outputs the actual HTML text to the browser, not the
> interpreted text.
> 
> Any idea ?
> 
> html_ok = """
> Content-Type: text/html\n
 > 
 > ...
 > """

Avoid the starting newline (before content-type).
Add at least TWO newlines after content-type.

Or use a package to handle the HTTP stuff for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cgi script not understood as html

2005-10-24 Thread Philippe C. Martin
the title should say "python cgi script html output not understood as html"


Philippe C. Martin wrote:

> Hi,
> 
> The following code outputs the actual HTML text to the browser, not the
> interpreted text.
> 
> Any idea ?
> 
> Regards,
> 
> Philippe
> import cgi
> import logging
> import auth #this is the one you must implement (or use SCF ;-)
> 
> html_ok = """
> Content-Type: text/html\n
>  "http://www.w3.org/TR/html4/loose.dtd";>\n
> \n
> \n
>   Access Granted\n
>   \n
>   \n
> \n
> \n
> Access Granted\n
> \n
> Welcome %s \n
> \n
> \n
> \n
> """
> 
> html_nok = """
> "Content-Type: text/html\n\n"
>  "http://www.w3.org/TR/html4/loose.dtd";>
> 
> 
> 
>   Access Granted
>   
>   
> 
> 
> Access Denied
> 
> 
> 
> 
> 
> """
> # DISPLAY ACCESS DENIED PAGE
> def Failure():
> print html_nok
> 
> #DISPLAY ACCESS GRANTED PAGE
> def Success(p_data):
> print html_ok % (p_data)

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


Re: Python cgi

2005-10-22 Thread jbrewer
I added enctype="multipart/form-data"  to the  tag, and that
seemed to solve it.  Thanks.

Jeremy

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


Re: Python cgi

2005-10-21 Thread Mike Meyer
"jbrewer" <[EMAIL PROTECTED]> writes:
> Also, I need to run an external program with my CGI script using
> something like os.system with flags from input forms, which is a major
> security risk.  Is it simply enough to test for flag.isalnum() or
> should I do more to prevent random programs from being run?  I should
> also do some minimal DOS protection as well, so information on how to
> do that simply would be appreciated as well.

Map the input data through a dictionary:

flags = dict(longflag = '-l', verboseflag = '-v', ...)
comflags = [flags[flag] for flag in flags if form[flag].value]
os.system(mycommand, *comflags)

or words to that effect. The critical thing is that data from over
the net never goes into the command, it's just used to look up values
in the dictionary, which provides strings you know are safe to pass to
the command.

The downside is that the client can only use flags your code knows
about. Of course, that's also an *upside*.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python cgi

2005-10-21 Thread Mitja Trampus
jbrewer wrote:
> I'm currently writing my first CGI script (in Python), and I keep
> getting an error I don't know how to address.  I'm not sure if this is
> a Python or Apache error, but I suspect it's an Apache config thing.

I suspect it's neither :)
Make sure your HTML form looks like

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


RE: Python CGI Script

2005-10-02 Thread Iyer, Prasad C

I guess your python script isn't getting executed.

a. I guess you might have to tweak the server if the script is not
getting executed.
b. Maybe your script is getting executed but you are not setting the
"Content-type" parameter which is essential for browser that it is an
html page.

Note :- Set "Content-type" to "text/html" I guess this should work


regards
prasad chandrasekaran










--- Cancer cures smoking

-Original Message-
From: Efrat Regev [mailto:[EMAIL PROTECTED]
Sent: Friday, September 30, 2005 4:20 PM
To: python-list@python.org
Subject: Python CGI Script

 Hello,

 I'm a data-structures course TA trying to write a python CGI script

for automatically compiling and testing students' projects.
Unfortunately, I've run into some questions while writing this, which I
couldn't solve with the various (and helpful) python-CGI documentation.
(It's possible that I'm posting to the wrong group; if so, I'd
appreciate suggestions for the appropriate group.)


1. In my HTML page, I have the following:





 In the above, submission_processor.py is the python CGI script. I
didn't write a URL in the action field, since I'm first testing
everyting on a local machine (running FC4). The first line of
submission_processor.py is

#!/usr/bin/python

and I've done

chmod +x submission_processor.py

 When I hit the "submit" button, my browser (Firefox on FC4) doesn't

run the script; it asks me whether it should open
submission_processor.py or save it to disk. I couldn't figure out why.

2. My HTML page has the option for an instructor to list the various
submissions and scores. Obviously, this should be inaccessible to
students. The instructor has a password for doing this, therefore.
Suppose I place the password inside a python script, and give this
script only +x permission for others. Is this  adequate as far as
security?


 Thanks in advance for answering these questions.


  Efrat


This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient,  you are not authorized 
to read, print, retain, copy, disseminate,  distribute, or use this message or 
any part thereof. If you receive this  message in error, please notify the 
sender immediately and delete all  copies of this message.

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


Re: Python CGI Script

2005-10-02 Thread Ivan Herman
Efrat,

I am afraid a CGI script is never *executed* by the browser. Instead, it sends
the URL to a server, expects the server to execute the script, and display the
server's response. If you just put a file name then (it seems, I never even
tried that) Firefox uses the local file store as a 'server' in that respect.

If you want to test a CGI script on your own machine, you should run a web
server on your own machine. That server should also be set up in a way that it
recognizes a '.py' file as a CGI script to be executed by Python (not all
servers may recognize the #!  trick...).

This may look scary, but it is not that bad. Apache has a number of precompiled
binary versions that you can install on your machine; you can also use servers
like W3C's jigsaw (this relies on Java) or others. These are all free and easy
to install and, well, manageable to configure. Actually, in case you run on a
MacOS X by any chance, Apache is already installed afaik...

I hope this helps

Ivan


 Original Message 
From: Efrat Regev <[EMAIL PROTECTED]>
To:
Subject: Python CGI Script
Date: 30/9/2005 12:50

> Hello,
> 
> I'm a data-structures course TA trying to write a python CGI script
> for automatically compiling and testing students' projects.
> Unfortunately, I've run into some questions while writing this, which I
> couldn't solve with the various (and helpful) python-CGI documentation.
> (It's possible that I'm posting to the wrong group; if so, I'd
> appreciate suggestions for the appropriate group.)
> 
> 
> 1. In my HTML page, I have the following:
> 
>  enctype="multipart/form-data">
> ...
> 
> 
> In the above, submission_processor.py is the python CGI script. I
> didn't write a URL in the action field, since I'm first testing
> everyting on a local machine (running FC4). The first line of
> submission_processor.py is
> 
> #!/usr/bin/python
> 
> and I've done
> 
> chmod +x submission_processor.py
> 
> When I hit the "submit" button, my browser (Firefox on FC4) doesn't
> run the script; it asks me whether it should open
> submission_processor.py or save it to disk. I couldn't figure out why.
> 
> 2. My HTML page has the option for an instructor to list the various
> submissions and scores. Obviously, this should be inaccessible to
> students. The instructor has a password for doing this, therefore.
> Suppose I place the password inside a python script, and give this
> script only +x permission for others. Is this  adequate as far as security?
> 
> 
> Thanks in advance for answering these questions.
> 
> 
>  Efrat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI Script

2005-10-02 Thread Steve Holden
Efrat Regev wrote:
>  Hello,
> 
>  I'm a data-structures course TA trying to write a python CGI script 
> for automatically compiling and testing students' projects. 
> Unfortunately, I've run into some questions while writing this, which I 
> couldn't solve with the various (and helpful) python-CGI documentation. 
> (It's possible that I'm posting to the wrong group; if so, I'd 
> appreciate suggestions for the appropriate group.)
> 
> 
> 1. In my HTML page, I have the following:
> 
>  enctype="multipart/form-data">
> ...
> 
> 
>  In the above, submission_processor.py is the python CGI script. I 
> didn't write a URL in the action field, since I'm first testing 
> everyting on a local machine (running FC4). The first line of 
> submission_processor.py is
> 
> #!/usr/bin/python
> 
> and I've done
> 
> chmod +x submission_processor.py
> 
>  When I hit the "submit" button, my browser (Firefox on FC4) doesn't 
> run the script; it asks me whether it should open 
> submission_processor.py or save it to disk. I couldn't figure out why.
> 
You also have to have the executable script inside a directory that is 
recognised as being a script directory (usually achieved with an Apache 
ScriptAlias directive), or have the server otherwise recognise .py files 
as executable (just setting the +x mode bit isn't enough).

In the absence of such knowledge the server just returns the content of 
the file rather than the content produced by *executing* the file.

> 2. My HTML page has the option for an instructor to list the various 
> submissions and scores. Obviously, this should be inaccessible to 
> students. The instructor has a password for doing this, therefore. 
> Suppose I place the password inside a python script, and give this 
> script only +x permission for others. Is this  adequate as far as security?
> 
That depends on whether you wanted to use HTTP security (provided 
automatically by the web server) or application security (provided by 
your code).

In the case of a script which is for general running but where some of 
the script's functionality shouldn't be generally available you are 
stuck with the latter. It's OK to have passwords in your script as long 
as you are sure that the script isn;t going to be served up as content 
like it currently is!

> 
>  Thanks in advance for answering these questions.
> 
> 
>   Efrat

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Python CGI and Firefox vs IE

2005-09-07 Thread dimitri pater
On 7 Sep 2005 11:10:00 -0700, Jason <[EMAIL PROTECTED]> wrote:
IE...
Yeah, I  know what you mean. Here's another one that doesn't work in IE, but it does work in Firefox:

canvas = pid.PILCanvas()

 canvas.drawRect(0,400, 500, 0, fillColor=pid.floralwhite, edgeColor=pid.maroon )



# display stuff

f = StringIO.StringIO()

canvas.save(f, format="png")

# does not work in MSIE, that sucks...

return 'data:image/png,' + urllib.quote(f.getvalue())



these are DATA URIs (http://www.howtocreate.co.uk/wrongWithIE/?chapter=Data%3A+URIs)

so do I now have to change my code because most people use IE? Probably I have to :-(
 Have to come up with a workaround, go back to the old .  I'mabout the only one who uses firefox in our facility.
Thanks for the reply and the link.--http://mail.python.org/mailman/listinfo/python-list-- 
All
truth passes through three stages. First, it is ridiculed. Second, it
is violently opposed. Third, it is accepted as being self-evident.Arthur Schopenhauer -Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI and Firefox vs IE

2005-09-07 Thread Jason
IE...

Have to come up with a workaround, go back to the old .  I'm
about the only one who uses firefox in our facility.

Thanks for the reply and the link.

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


Re: Python CGI and Firefox vs IE

2005-09-07 Thread infidel
> I see what's happening, but I'm at a loss to figure out what to do
> about it.  Any help would be appreciated.

Try giving the buttons different name attributes.

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


Re: Python CGI and Firefox vs IE

2005-09-07 Thread Stephan Diehl
On Wed, 07 Sep 2005 10:50:15 -0700, Jason wrote:

> Hey y'all, this falls under the murky realm of HTML, CGI and
> Python...and IE.
> 
> Python 2.4, using CGI to process a form.
> 
> Basically I've got 3 buttons.  Here's the HTML code:
> 
> 
> All
> Servers
>  type='submit'>WKPEA1
>  type='submit'>WKNHA2
> 
> 
> 
> And the code that's messing things up:
> 

No, here you are wrong. IE doesn't work as expected with buttons.
See
http://www.solanosystems.com/blog/archives/2005/04/12/the-submit-button-problem/

This has nothing to do with Python.
---
Stephan
> jason

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


Re: Python-cgi web or Perl-cgi script doubt

2005-07-30 Thread Michael Sparks
praba kar wrote:
>I want to know difference between
> Python-cgi and Perl-cgi and also I want
> to which one is efficient from the performance.

Possibly the most important difference between the two is when you're using
JUST cgi - ie no mod_perl, no mod_python, etc. With python, if your cgi is
structured to use more than one file, then your programs can be compiled
and stored on disk (compiled to something called bytecode). This can just
be loaded and executed immediately on subsequent runs.

With perl, the program needs to be loaded and recompiled with each run.

For small CGI systems this difference is negligible, but for large CGI based
systems (eg when using a large framework), these differences can become
very important - if you do not have the option to use mod_perl/mod_python
or similar.

However, many people running large web systems do tend to use mod_perl and
friends when using perl which discounts this argument pretty much
completely.

That said, I'd suggest looking to see *what* you want to do, look at what
*tools* are available and *then* decide which *language* to use. Personally
I find python nicer for this sort of things these days - larger because it
naturally encourages better strutcure. (And this is after having using perl
day-in, day-out for 5 years, and still liking perl :-)

Hope that's of some use,


Michael.

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


Re: Python-cgi or Perl-cgi script doubt

2005-07-29 Thread EP
Prabahar wrote:

>I want to know difference between
> Python-cgi and Perl-cgi and also I want
> to which one is efficient from the performance.


The difference between a cgi program written in Perl and a cgi program written 
in Python is the choice of programming language.  Both work quite well.  You 
probably want to use whichever programming language you like best, and that can 
only be discovered from writing programs in both.

In terms of "efficient"  (efficiency) , are you talking about how much memory 
the program uses, how fast the program executes, or how much time it takes to 
write and debug the program?  There are differences between the two in these 
regards, but I do not have any reliable information that quantifies those 
differences, and the differences are likely to vary greatly depending on the 
nature and length of the program, and how efficiently written the code is.

I think, generally, if you really like programming in Perl, there is probably 
no reason not to use it (at least for typical/short cgi programs) - it has been 
the default choice for years; conversely, if you really like programming in 
Python, you will probably be happy to tackle any challenges associated with 
using it for cgi.


Notes:
Perl cgi execution is generally offered by all hosts that offer cgi; Python cgi 
execution is offered by fewer hosts (but some of those hosts are really great).

With either language, if execution "performance" is a concern, you may want to 
use something along the lines of mod_python or mod_perl which embed a 
persistent interpreter in your web server. This lets you avoid the overhead of 
starting an external interpreter and avoids the penalty of Perl/Python start-up 
time, giving faster time to execution.

Was this at all the information you were looking for?  Why do I think you may 
have intended a very technical question?  If so, you may have to be a little 
more specific about the sort of differences you are interested in understanding.


Eric


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


Re: Python CGI discussion Group

2005-03-15 Thread Dmitry A.Lyakhovets
On 15 Mar 2005 07:05:59 -0800
"Fuzzyman" <[EMAIL PROTECTED]> wrote:

> There is a `web design` group over on google-groups.
> http://groups-beta.google.com/group/wd
> 
> It's brief is for ``Discussion of web design (html, php, flash,
> wysiwig, cgi, perl, python, css, design concepts, etc.).``, but it's
> very quiet. I'd love to see it become a discussion forum for Python
> CGIs and associated issues (web design, the http protocol etc).

I'd also be happy to see that. May be somebody know an alive discussion 
on Python CGI's?

> 
> Regards,
> 
> Fuzzy
> http://www.voidspace.org.uk/python/cgi.shtml
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

-- 
Best regards,
Dmitry A. Lyakhovets  mailto:[EMAIL PROTECTED]
visit http://www.aikido-groups.ru -- Aikido Dojo site
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Wed, 19 Jan 2005 12:15:18 -0800, Paul Rubin wrote:

> Dfenestr8 <[EMAIL PROTECTED]> writes:
>> No glaring security holes that you noticed? Other than being able to
>> hide things in html tags?
> 
> Looks like you can also embed arbitrary javascript (I just tried it). I
> haven't looked at the script itself yet.

fixed that.
try doing it now..

http://funkmunch.net/~pirch/cgi-bin/betaforum/pptopic.py

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


Re: python/cgi/html bug

2005-01-19 Thread Paul Rubin
Dfenestr8 <[EMAIL PROTECTED]> writes:
> No glaring security holes that you noticed? Other than being able to hide
> things in html tags?

Looks like you can also embed arbitrary javascript (I just tried it).
I haven't looked at the script itself yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Wed, 19 Jan 2005 04:32:04 -0800, Fuzzyman wrote:

> This looks very good.
> I've been looking for a python messageboard CGI for a long time.
> 

Thanx!

No glaring security holes that you noticed? Other than being able to hide
things in html tags?

> If you wanted to add user accounts/login/admin etc. you could use 'Login
> Tools'. This is a python module built especially to do that. It also
> provides a convenient way of saving user preferences etc.
> 
> http://www.voidspace.org.uk/python/logintools.html
> 
> If you want any help using it then feel free to ask.
> 
> Regards,

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


Re: python/cgi/html bug

2005-01-19 Thread Dfenestr8
On Tue, 18 Jan 2005 21:50:58 -0800, Dan Bishop wrote:

> 
> Dfenestr8 wrote:
>> Hi.
>>
>> I've written a cgi messageboard script in python, for an irc chan I
> happen
>> to frequent.
>>
>> Bear with me, it's hard for me to describe what the bug is. So I've
>> divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT
> THE
>> BUG IS.
>> ...
>> The problem is when someone posts a new topic, and that topic happens
> to
>> have "" double quotes, or any other strange character, some strange
>> glitches occur.
> 
> Use cgi.escape(topic, True) to convert HTML special characters to the
> equivalent ampersand escape sequences.

Thanx.

Seems to work now. :)

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


Re: python/cgi/html bug

2005-01-18 Thread Dan Bishop

Dfenestr8 wrote:
> Hi.
>
> I've written a cgi messageboard script in python, for an irc chan I
happen
> to frequent.
>
> Bear with me, it's hard for me to describe what the bug is. So I've
> divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT
THE
> BUG IS.
> ...
> The problem is when someone posts a new topic, and that topic happens
to
> have "" double quotes, or any other strange character, some strange
> glitches occur.

Use cgi.escape(topic, True) to convert HTML special characters to the
equivalent ampersand escape sequences.

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