Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread Chris Angelico
On Tue, Sep 22, 2015 at 7:36 AM,   wrote:
> Thank you very much. Can I write .py pages like in PHP or should I
> use a framework like Django, Web2py or TurboGears?

I recommend using WSGI and a framework that uses it (my personal
preference is Flask, but the above will also work). Here are a couple
of simple sites:

https://github.com/Rosuav/Flask1
https://github.com/Rosuav/MinstrelHall

You can see them in operation here:

http://rosuav.com/1/
http://minstrelhall.com/

Note how URLs are defined in the code, rather than by having a bunch
of loose files (the way a PHP web site works). This makes it a lot
easier to group things logically, and utility lines like redirects
become very cheap. The maintenance burden is far lighter with this
kind of one-file arrangement.

These sites are really tiny, though, so if you have something a bit
bigger, you'll probably want to split things into multiple files. Good
news! You can do that, too - it's easy enough to split on any boundary
you find logical.

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


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
On Monday, September 21, 2015 at 10:29:48 PM UTC+2, alister wrote:
> On Mon, 21 Sep 2015 12:51:09 -0700, tropical.dude.net wrote:
> 
> > On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical...@gmail.com
> > wrote:
> >> On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote:
> >> > In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com>
> >> > tropical.dude@gmail.com writes:
> >> > 
> >> > > print("Content-Type: text/html;charset=utf-8")
> >> > > print("Hello World!")
> >> > 
> >> > As I recall, you must have a blank line between the headers and the
> >> > content.
> >> > 
> >> > But that may or may not be your problem, as you haven't told us
> >> > exactly what is going wrong.
> >> > 
> >> > --
> >> > John Gordon   A is for Amy, who fell down the stairs
> >> > gor...@panix.com  B is for Basil, assaulted by bears
> >> > -- Edward Gorey, "The Gashlycrumb
> >> > Tinies"
> >> 
> >> I am new to Ubuntu, is there a command so I can find out what the
> >> problem is?
> > 
> > The only error I can see right now is forbedden, you don't have
> > permission to access /index.py on this server.
> 
> this is not a linux permissions error it is an error with the apache 
> configuration you need to check roe acache config files
> (you may also want to investigate WSGI as CGI is outdated) 
> 
> 
> 
> -- 
> Perfection is acheived only on the point of collapse.
> - C. N. Parkinson

Thank you very much. Can I write .py pages like in PHP or should I
use a framework like Django, Web2py or TurboGears? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread alister
On Mon, 21 Sep 2015 12:51:09 -0700, tropical.dude.net wrote:

> On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical...@gmail.com
> wrote:
>> On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote:
>> > In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com>
>> > tropical.dude@gmail.com writes:
>> > 
>> > > print("Content-Type: text/html;charset=utf-8")
>> > > print("Hello World!")
>> > 
>> > As I recall, you must have a blank line between the headers and the
>> > content.
>> > 
>> > But that may or may not be your problem, as you haven't told us
>> > exactly what is going wrong.
>> > 
>> > --
>> > John Gordon   A is for Amy, who fell down the stairs
>> > gor...@panix.com  B is for Basil, assaulted by bears
>> > -- Edward Gorey, "The Gashlycrumb
>> > Tinies"
>> 
>> I am new to Ubuntu, is there a command so I can find out what the
>> problem is?
> 
> The only error I can see right now is forbedden, you don't have
> permission to access /index.py on this server.

this is not a linux permissions error it is an error with the apache 
configuration you need to check roe acache config files
(you may also want to investigate WSGI as CGI is outdated) 



-- 
Perfection is acheived only on the point of collapse.
- C. N. Parkinson
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical...@gmail.com wrote:
> On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote:
> > In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com> 
> > tropical.dude@gmail.com writes:
> > 
> > > print("Content-Type: text/html;charset=utf-8")
> > > print("Hello World!")
> > 
> > As I recall, you must have a blank line between the headers and the
> > content.
> > 
> > But that may or may not be your problem, as you haven't told us exactly
> > what is going wrong.
> > 
> > -- 
> > John Gordon   A is for Amy, who fell down the stairs
> > gor...@panix.com  B is for Basil, assaulted by bears
> > -- Edward Gorey, "The Gashlycrumb Tinies"
> 
> I am new to Ubuntu, is there a command so I can find out what the problem is?

The only error I can see right now is forbedden, you don't have permission to 
access /index.py on this server.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote:
> In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com> 
> tropical.dude@gmail.com writes:
> 
> > print("Content-Type: text/html;charset=utf-8")
> > print("Hello World!")
> 
> As I recall, you must have a blank line between the headers and the
> content.
> 
> But that may or may not be your problem, as you haven't told us exactly
> what is going wrong.
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

I am new to Ubuntu, is there a command so I can find out what the problem is?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
On Monday, September 21, 2015 at 9:30:11 PM UTC+2, Albert Visser wrote:
> On Mon, 21 Sep 2015 20:41:13 +0200,  wrote:
> 
> > Hello everybody,
> >
> (...)
> >
> > I created index.py:
> > #!/usr/bin/env python
> > # -*- coding: UTF-8 -*-# enable debugging
> > import cgitb
> >
> > cgitb.enable()
> > print("Content-Type: text/html;charset=utf-8")
> > print("Hello World!")
> >
> > But it is still not working.
> >
> > Can anybody help me out?
> >
> > Thanks in advance.
> 
> Which Python are you running? If it's Python 3, change the shebang  
> accordingly because "python" is assuming Python 2.
> 
> -- 
> Vriendelijke groeten / Kind regards,
> 
> Albert Visser
> 
> Using Opera's mail client: http://www.opera.com/mail/

I am running python3.4
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread John Gordon
In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com> 
tropical.dude@gmail.com writes:

> print("Content-Type: text/html;charset=utf-8")
> print("Hello World!")

As I recall, you must have a blank line between the headers and the
content.

But that may or may not be your problem, as you haven't told us exactly
what is going wrong.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
On Monday, September 21, 2015 at 9:20:22 PM UTC+2, sohca...@gmail.com wrote:
> On Monday, September 21, 2015 at 11:41:54 AM UTC-7, tropical...@gmail.com 
> wrote:
> > Hello everybody,
> > 
> > I installed the LAMP stack on in Ubuntu, but I am having
> > problems configuring Apache to run python CGI scripts.
> > 
> > I ran:
> > sudo a2enmod cgi
> > 
> > I added to apache2.conf
> > 
> > Options +ExecCGI
> > AddHandler cgi-script .py
> > 
> > 
> > I created index.py:
> > #!/usr/bin/env python
> > # -*- coding: UTF-8 -*-# enable debugging
> > import cgitb
> > 
> > cgitb.enable()
> > print("Content-Type: text/html;charset=utf-8")
> > print("Hello World!")
> > 
> > But it is still not working.
> > 
> > Can anybody help me out?
> > 
> > Thanks in advance.
> 
> "It isn't working" is about as useful as telling a mechanic "My car doesn't 
> work" without giving details on what exactly is happening.
> 
> What exactly isn't working?  What error message are you getting?
> 
> The first thing I would check is to make sure the permissions on index.py are 
> set to allow execution.  It is easy to forget to do that.

The error message that I am receiving in my browser is:
403: You don't have permission to access /index.py on this server.

The permissions of index.py is 755
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread Albert Visser

On Mon, 21 Sep 2015 20:41:13 +0200,  wrote:


Hello everybody,


(...)


I created index.py:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging
import cgitb

cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print("Hello World!")

But it is still not working.

Can anybody help me out?

Thanks in advance.


Which Python are you running? If it's Python 3, change the shebang  
accordingly because "python" is assuming Python 2.


--
Vriendelijke groeten / Kind regards,

Albert Visser

Using Opera's mail client: http://www.opera.com/mail/
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread sohcahtoa82
On Monday, September 21, 2015 at 11:41:54 AM UTC-7, tropical...@gmail.com wrote:
> Hello everybody,
> 
> I installed the LAMP stack on in Ubuntu, but I am having
> problems configuring Apache to run python CGI scripts.
> 
> I ran:
> sudo a2enmod cgi
> 
> I added to apache2.conf
> 
> Options +ExecCGI
> AddHandler cgi-script .py
> 
> 
> I created index.py:
> #!/usr/bin/env python
> # -*- coding: UTF-8 -*-# enable debugging
> import cgitb
> 
> cgitb.enable()
> print("Content-Type: text/html;charset=utf-8")
> print("Hello World!")
> 
> But it is still not working.
> 
> Can anybody help me out?
> 
> Thanks in advance.

"It isn't working" is about as useful as telling a mechanic "My car doesn't 
work" without giving details on what exactly is happening.

What exactly isn't working?  What error message are you getting?

The first thing I would check is to make sure the permissions on index.py are 
set to allow execution.  It is easy to forget to do that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread tropical . dude . net
Hello everybody,

I installed the LAMP stack on in Ubuntu, but I am having
problems configuring Apache to run python CGI scripts.

I ran:
sudo a2enmod cgi

I added to apache2.conf

Options +ExecCGI
AddHandler cgi-script .py


I created index.py:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging
import cgitb

cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print("Hello World!")

But it is still not working.

Can anybody help me out?

Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


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


Python CGI

2014-05-19 Thread Christian
Hi,

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.

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


Re: Data transfer from Python CGI to javascript

2013-08-09 Thread MRAB

On 09/08/2013 07:53, e...@cleantechsolution.in wrote:

I have written the following program
#!c:\Python27\Python.exe
import cgi, cgitb;
import sys, serial
cgitb.enable()
ser = serial.Serial('COM27', 9600)
myvar = ser.readline()
print "Content-type:text/html\n\n"
print """



Real Time Temperature

   
 window.onload = startInterval;
 function startInterval()
 {
 setInterval("startTime();",1000);
 }

 function startTime(myvar)
 {
 document.getElementById('mine').innerHTML ="Temperature" 
+parseInt(myvar);

 }
   


Real Time Temperature:


"""

It is giving an output of 'NaN' in the output.
If the python program is run alone it is giving the correct output.
Can anyone please help.
Is it also possible to separate the python and the javascript to two different 
files. If so how will I get/transfer the data in/from HTML .
Thanks


At a guess I'd say that it's because you have:

setInterval("startTime();",1000);

which will call 'startTime' with no arguments, but:

function startTime(myvar)

which means that it's expecting an argument.

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


Data transfer from Python CGI to javascript

2013-08-09 Thread engg
I have written the following program 
#!c:\Python27\Python.exe
import cgi, cgitb;
import sys, serial
cgitb.enable()
ser = serial.Serial('COM27', 9600)
myvar = ser.readline()
print "Content-type:text/html\n\n"
print """



Real Time Temperature

  
window.onload = startInterval;
function startInterval()
{
setInterval("startTime();",1000);
}

function startTime(myvar)
{
document.getElementById('mine').innerHTML ="Temperature" 
+parseInt(myvar);

}
  


Real Time Temperature:


"""

It is giving an output of 'NaN' in the output. 
If the python program is run alone it is giving the correct output. 
Can anyone please help.
Is it also possible to separate the python and the javascript to two different 
files. If so how will I get/transfer the data in/from HTML . 
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with running python cgi scripts through my browser

2012-04-20 Thread kreta06
Dear Python Tutors,

I am having problems trying to send an email (using the smtplib module ) to
send an email to myself over my browser using a python script, which is
being called by an html form that I have created. My python cgi script is
located in my cgi-bin directory, which I had made sure that in my httpd
configuration, I had added the python extensions so that it can be run as a
cgi script over my browser. If I run my python script directly on the
commandline, I am able to send an email to myself and receive it.
However, when I try to do the same and run it from my html form, it doesn't
work. I'm sure I'm missing something here, but just can't figure out what.
My suspicions could be that to send an email over the browser requires a
specific format, which I could not figure out.
Below is my cgi script and errors that I get when I run the cgi script.

Any help would be appreciated.

Many thanks,
Sue


-
my script:

import cgi
import string,sys
import smtplib
import cgitb
cgitb.enable()
sys.stderr = sys.stdout


def main():
print "Content-type: text/html\n"
form = cgi.FieldStorage()
if form.has_key("firstname") and form["firstname"].value != "":
result = "Name: " + form["firstname"].value +
"Favorite Color(s): " + form["colors"].value + "Favorite Drinks(s): "
+ str(form.getlist("drinks")) + "Email: " + form["email"].value
return result
else:
print "Please enter your firstname!"


TEXT = main()


FROM = "myem...@gmail.com"
TO = "myem...@gmail.com"
SUBJECT = "Second try"

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM,",".join(TO), SUBJECT, TEXT)

# Send the mail
server2 = smtplib.SMTP("localhost")
server2.sendmail(FROM, TO, message)
server2.quit()

-

Error  I get:

 /usr/lib/python2.6/cgitb.py:173: DeprecationWarning: BaseException.message
has been deprecated as of Python 2.6 value =
pydoc.html.repr(getattr(evalue, name))

**Python 2.6.6: /usr/bin/python
Fri Apr 20 15:13:06 2012

A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
  /var/www/cgi-bin/action.py in **()37
38 # Send the mail
39 server2 = smtplib.SMTP("localhost")
40 server2.sendmail(FROM, TO, message)
41 server2.quit()
 server2 *undefined*, *smtplib* = , smtplib.*SMTP* = 
/usr/lib/python2.6/smtplib.py in *__init__*(self=,
host='localhost', port=0, local_hostname=None, timeout=)
  237 self.default_port = SMTP_PORT
   238 if host:
   239 (code, msg) = self.connect(host, port)
   240 if code != 220:
   241 raise SMTPConnectError(code, msg)
 code *undefined*, msg *undefined*, *self* = , self.*
connect* = >, *host* =
'localhost', *port* = 0   /usr/lib/python2.6/smtplib.py in
*connect*(self=, host='localhost', port=25)   293
 if not port: port = self.default_port
   294
 if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
   295 self.sock = self._get_socket(host, port, self.timeout)
   296 (code, msg) = self.getreply()
   297 if self.debuglevel > 0: print>>stderr, "connect:", msg
 *self* = , self.sock *undefined*, self.*_get_socket* =
>, *host* =
'localhost', *port* = 25, self.*timeout* = 
/usr/lib/python2.6/smtplib.py in *_get_socket*(self=, port='localhost', host=25, timeout=)   271
 # and just alter the socket connection bit.
   272
 if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
   273 return socket.create_connection((port, host), timeout)
   274
   275 def connect(self, host='localhost', port = 0):
 *global* *socket* = , socket.*create_connection* = , *port* = 'localhost', *host* = 25, *timeout* =/usr/lib/python2.6/socket.py in
*create_connection*(address=('localhost',
25), timeout=)   563 except error, msg:
   564 if sock is not None:
   565 sock.close()
   566
   567 raise error, msg
 *global* *error* = , *msg* = error(13, 'Permission
denied')

**: [Errno 13] Permission denied
  args = (13, 'Permission denied')
  errno = 13
  filename = None
  message = ''
  strerror = 'Permission denied'
-- 
http://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


Python - CGI-BIN - Apache Timeout Problem

2012-03-02 Thread Sean Cavanaugh (scavanau)
Hello List,

 

Would appreciate some insight/help, ran out of ideas...

 

BRIEF OVERVIEW:

 

I am trying to create a simple webserver gui wrapper for a set of
scripts I developed to test some of our firewalls here at Cisco.  Being
that the total amount of engineer that will ever probably use this is 4
people and my limited python experience I just decided to do a quick
cgi-bin solution.  I control the machine with the webserver on em0 where
I do my fw testing on em1/em2.

 

Browser goes to http://webserver/main.py-> main.py executes a
script->tests.py ->test.py imports my engine v6tester_main.py which is a
series of functions I wrote. tests.py kicks of whatever test main.py
wanted.  

 

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()

print output

proc.stdout.close()

 

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.

 

I know it's not a permissions issue or setup issue b/c I did a proof of
concept where I just fired one simple pcap and it works fine (reported
back just like it would if I ran it on the command line).. it has
something to do with either the amount of prints out the script is
doing, or the timing.  I see no problems except the timeout (nothing in
logs: /var/log/http-error.log).  My script takes about 8 secounds to
run.  It does use threading but I wouldn't think that would mess it up.

 

BTW: I posted here if this helps anyone:
http://stackoverflow.com/questions/9524758/cgi-bin-timing-timeout-on-fre
ebsd-apache22

 

 

Thanks in advance for any ideas.  I can include the whole main.py if
that would help.

 



Sean Cavanaugh

Cisco Systems

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


python cgi webpage won't redirect before background children processes finish

2011-02-22 Thread Yingjie Lin
Hi all,

I have a python cgi script which looks like this:

[CODE STARTING HERE]
open('x')
print 'Content-Type: text/html\n\n'
..
print '' % myURL
..
### after printing the webpage
os.system('python myfile.py')
logfile.write('END OF SCRIPT')
logfile.close()
[CODE ENDING]

Question: I want this cgi webpage to automatically redirect to myURL after 15 
seconds. 
As soon as the execution of this script finishes, the corresponding job 
disappears from 
ps command output, the webpage is displayed and the log file is written. 
However, the 
webpage doesn't redirect after 15 seconds unless the background child process 
'python myfile.py' finishes by then.

Is this problem caused by initialing the children job through os.system() ? 
Does any one 
know what I need to change to make the redirection work before background 
children processes finish?

Thank you very much!

Yingjie
-- 
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


Python CGI windows

2010-08-13 Thread Srikanth N
Dear All,

I Have certain clarification in python CGI.

I use Python IDLE

*1. How do we execute CGI Scripts in Windows?
2. How do i configure the Server?(If i use WAMP,XAMPP)
3. Is mod_python required for python cgi?
*
Someone Please revert back to me with the solution for the same.I would be
at-most thankful


-- 
Thanks & Regards,
Srikanth.N
-- 
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


Python, CGI and Sqlite3

2010-04-13 Thread Majdi Sawalha
Dear list members,

I am writing CGI program that reads a text feild and uses with select statement 
to retrieve data from a database file using sqlite3. the program behaived very 
strange as it does not recognizes the 

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.
i tried it also by prining the output to a text file instead using cgi web 
folder, and it worked.

Looking forward to hearing from you.

best regards,

Majdi Sawalha

Faculty of Engineering
School of Computing
University of Leeds
Leeds, LS2 9JT
UK
http://www.comp.leeds.ac.uk/sawalha 


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


Re: Converting Python CGI to WSGI scripts

2010-03-17 Thread python
Sebastian/John,

Thank you very much for your feedback. 

John: I initially missed the nuance of WSGI scripts being function
calls. I suspect your tip has saved me a lot of pain :)

Regards,

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


Re: Converting Python CGI to WSGI scripts

2010-03-16 Thread John Nagle

Sebastian Bassi wrote:

On Tue, Mar 16, 2010 at 2:18 PM,   wrote:

I have a few dozen simple Python CGI scripts.
Are there any advantages or disadvantages to rewriting these CGI scripts as
WSGI scripts?


It depends of the script. WSGI should be faster since you don't start
a Python instance for each call (as in CGI).


   It's almost always faster.  But be careful about global state.
Remember that WSGI/FCGI programs are really functions, called
over and over with a new transaction on each call.  So your
function has to be reusable.

   Things like initializing global variables at program load time,
rather than when the main function is called, may give trouble.
Also, be careful about leaving files, database connections, and
sockets open after the main function returns.

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


Re: Converting Python CGI to WSGI scripts

2010-03-16 Thread Sebastian Bassi
On Tue, Mar 16, 2010 at 2:18 PM,   wrote:
> I have a few dozen simple Python CGI scripts.
> Are there any advantages or disadvantages to rewriting these CGI scripts as
> WSGI scripts?

It depends of the script. WSGI should be faster since you don't start
a Python instance for each call (as in CGI).

-- 
Sebastián Bassi. Diplomado en Ciencia y Tecnología.

Curso de Python en un día: http://bit.ly/cursopython
Python for Bioinformatics: http://tinyurl.com/biopython

Non standard disclaimer: READ CAREFULLY. By reading this email,
you agree, on behalf of your employer, to release me from all
obligations and waivers arising from any and all NON-NEGOTIATED
agreements, licenses, terms-of-service, shrinkwrap, clickwrap,
browsewrap, confidentiality, non-disclosure, non-compete and
acceptable use policies ("BOGUS AGREEMENTS") that I have
entered into with your employer, its partners, licensors, agents and
assigns, in perpetuity, without prejudice to my ongoing rights and
privileges. You further represent that you have the authority to release
me from any BOGUS AGREEMENTS on behalf of your employer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting Python CGI to WSGI scripts

2010-03-16 Thread python
I have a few dozen simple Python CGI scripts.

Are there any advantages or disadvantages to rewriting these CGI
scripts as WSGI scripts?

Apologies if my terminology is not correct ... when I say WSGI
scripts I mean standalone scripts like the following simplified
(as an example) template:

import sys
def application(environ, start_response):
output = 'Welcome to your mod_wsgi website! It
uses:\n\nPython %s' % sys.version
response_headers = [
('Content-Length', str(len(output))),
('Content-Type', 'text/plain'),
]
start_response('200 OK', response_headers)
return [output]

When I say script I don't mean classic WSGI application in the
sense of a .serve_forever() loop coordinating a bunch of related
scripts - I mean individual, standalone scripts.

Hope this makes sense :)

Thank you,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best performance for storage of server information for python CGI web app?

2009-11-28 Thread Aahz
In article <58e5cd75-75be-4785-8e79-490364396...@e31g2000vbm.googlegroups.com>,
davidj411   wrote:
>
>i was also thinking about using SQL Lite with one DB to store all the
>info. with this option, i would not have to worry about concurrent
>updates, but as the file size increases, i could expect performance to
>suffer again?

Depends what you mean by "suffer".  Performance always decreases as size
gets larger unless you take specific steps (such as better algorithms or
bigger hardware).  Using indexes should give SQLite reasonable
performance; you can always upgrade to a faster SQL implementation or
switch to another kind of storage.  But honestly, until you get to
millions of records, you should be fine with SQLite.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.  
-- 
http://mail.python.org/mailman/listinfo/python-list


best performance for storage of server information for python CGI web app?

2009-11-18 Thread davidj411
I am wondering what will give me the best performance for storing
information about the servers in our environment.
currently i store all info about all servers in a single shelve file,
but i have concerns.
1) as the size of the shelve file increases, will performance suffer ?
2) what about if 2 updates occur at the same time to the shelve file?
when a shelve file is opened, is the whole file read into memory?

if either scenario (1 or 2) is true, then should i think about
creating a shelve file per server?
i was also thinking about using SQL Lite with one DB to store all the
info.
with this option, i would not have to worry about concurrent updates,
but as the file size increases, i could expect performance to suffer
again?

I am running Python 2.6 CGI scripts on Apache web server on windows
platform. they interact with the current shelve file to pull info or
request info from a python service which will go collect the info and
put it into the shelve file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In python CGI, how to pass "hello" back to a javascript function as an argument at client side?

2009-10-13 Thread Piet van Oostrum
>>>>> zxo102  (z) wrote:

>z> Hi everyone,
>z> How can I pass a string generated from python cgi at server side
>z> to a
>z> javascript function as an argument at client side?

>z>  I want test.py to "return"  a "hello" back so the javascript function
>z> load takes "hello" as argument like  load("hello").

>z> 2. server side: test.py
>z> ...
>z> #!c:\python24\python.exe

>z> def main():
>z>message = 'hello'
>z>#return message

>z> main()
>z> ...

>z> Any ideas?

CGI scripts return stuff by printing it, or more generally writing to
stdout.

So print message should do. The rest is not a Python question but a
Javascript question.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In python CGI, how to pass "hello" back to a javascript function as an argument at client side?

2009-10-13 Thread Bruno Desthuilliers

zxo102 a écrit :

Hi everyone,
How can I pass a string generated from python cgi at server side
to a
javascript function as an argument at client side?



This is common HTTP / javascriot stuff - nothing related to Python. 
First learn about the HTTP protocol - something you obviously need if 
doing web development -, then eventually google for XMLHttpRequest (or 
'ajax').


To make a long story short: the client side doesn't give a damn about 
how the server-side works - it requests an url (-> read the part about 
"HTTP Request" in the rfc), waits for the response (-> read the part 
about "HTTP Response" in the rfc), and whatever it wants with the 
response. FWIW, HTTP requests can have a "query string" containing 
arguments.


From the server-side POV, your CGI script doesn't "return" anything - 
it generates a HTTP response, which will be sent back to the client by 
Apache.

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


In python CGI, how to pass "hello" back to a javascript function as an argument at client side?

2009-10-12 Thread zxo102
Hi everyone,
How can I pass a string generated from python cgi at server side
to a
javascript function as an argument at client side?

Here is my case:

1. client side:
 "load" is a javascript function in a html page. It starts the
python CGI "test.py" via Apache:


...
load("test.py" );
...

...


 I want test.py to "return"  a "hello" back so the javascript function
load takes "hello" as argument like  load("hello").

2. server side: test.py
...
#!c:\python24\python.exe

def main():
   message = 'hello'
   #return message

main()
...

Any ideas?


Thanks in advance for your help.


ouyang

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


Serving html and python cgi through BaseHTTPServer.py

2009-04-22 Thread Mads Nielsen
Hello all.

im tinkering with some beginner cgi stuff in python. (form processing)
i have a basic html document with a form and some inputs and i have a cgi.py
file to process the form.

how does one serve html and python cgi through the BaseHTTPServer included
with python 2.6 ?

i have tried to go to http://localhost:8000/index.html but no go. i get a
Error response 501 Unsupported method ('GET').

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


Re: Unix Change Passwd Python CGI

2009-02-25 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Derek Tracy wrote:
> Apache is running on the same system that needs the password changed.  I
> need to keep security high and can not install additional modules at
> this time.
> 
> I just need a general direction to start looking, and I do not have
> expect installed on the system.

I recommend looking in the Samba source code where they have a program
that does just that.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkmlGVcACgkQmOOfHg372QTZHACdFG0+Ls2Su/jRqkc4YZyxXK35
N7AAoNKfd7bMypR7b6Ex6auaU/9D4rKa
=POal
-END PGP SIGNATURE-

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


Re: Unix Change Passwd Python CGI

2009-02-24 Thread James Matthews
IMHO That sounds like the biggest security hole I can think of. Anyways you
can open a pipe to passwd. to have the change there password.

James

On Tue, Feb 24, 2009 at 5:19 PM, Derek Tracy  wrote:

> I am using python version 2.5.1 and need to create a python cgi application
> to allow a user to change their unix password.
>
> Apache is running on the same system that needs the password changed.  I
> need to keep security high and can not install additional modules at this
> time.
>
> I just need a general direction to start looking, and I do not have expect
> installed on the system.
>
> Any ideas would be wonderful!
>
> R/S --
> -
> Derek Tracy
> trac...@gmail.com
> -
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
http://www.goldwatches.com/

http://www.jewelerslounge.com/
--
http://mail.python.org/mailman/listinfo/python-list


Unix Change Passwd Python CGI

2009-02-24 Thread Derek Tracy
I am using python version 2.5.1 and need to create a python cgi application
to allow a user to change their unix password.

Apache is running on the same system that needs the password changed.  I
need to keep security high and can not install additional modules at this
time.

I just need a general direction to start looking, and I do not have expect
installed on the system.

Any ideas would be wonderful!

R/S --
-
Derek Tracy
trac...@gmail.com
-
--
http://mail.python.org/mailman/listinfo/python-list


Re: small python-cgi wiki?

2009-01-28 Thread Дамјан Георгиевски
> I'm looking to set up a small private wiki, and am looking for
> recommendations.
> 
> Some sort of CGI based package that I could just untar somewhere web
> accessable via Apache would be great.

http://hatta.sheep.art.pl/About
· single file
· stores stuff in mercurial.
· it's WSGI, so yes you can run it as CGI too 
(wsgiref.handlers.CGIHandler)
http://hatta.sheep.art.pl/Features

-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?

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


Re: small python-cgi wiki?

2009-01-28 Thread Petite Abeille


On Jan 28, 2009, at 6:02 PM, Bernard Rankin wrote:

I'm looking to set up a small private wiki, and am looking for  
recommendations.


Some sort of CGI based package that I could just untar somewhere web  
accessable via Apache would be great.


You might be interested by Nanoki, a small, simple wiki engine.

Online demo:

http://svr225.stepx.com:3388/search?q=python

http://svr225.stepx.com:3388/nanoki

One thing though... it's not Python :)

Cheers,

--
PA.
http://alt.textdrive.com/nanoki/

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


Re: small python-cgi wiki?

2009-01-28 Thread excord80
On Jan 28, 12:02 pm, Bernard Rankin  wrote:
>
> I'm looking to set up a small private wiki, and am looking for 
> recommendations.
>
> Some sort of CGI based package that I could just untar somewhere web 
> accessable via Apache would be great.

There are a number of them listed at 
http://wiki.python.org/moin/PythonWikiEngines
. You might have a look at PikiPiki.
--
http://mail.python.org/mailman/listinfo/python-list


small python-cgi wiki?

2009-01-28 Thread Bernard Rankin
Hello,

I'm looking to set up a small private wiki, and am looking for recommendations.

Some sort of CGI based package that I could just untar somewhere web accessable 
via Apache would be great.

Any ideas?

Thanks,
:)


  

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


Re: using subprocess module in Python CGI

2009-01-08 Thread ANURAG BAGARIA
Dear Matt,

Thank you for your answer.
This script is just a kind of test script so as to actually get it started
on doing any simple job. The actual process would be much more complicated
where in I would like to extract the tar file and search for a file with
certain extension and this file would be given as input to another program
installed on the server. Later on I would also like to use process.wait() so
that I can get a status of the job execution and completion from the server
and this information can be displayed to the users on the web-page where
they submit their jobs. As to what I understand subprocess.call() would be
the best in that case. Please correct, if I am wrong.

The whole process is like a user submitting a tar file via the web-browser
with some data and getting back the processed results in the form of a new
tar file after performing a few operations on the files submitted as input
tar file.

Thanking you once again for your valuable time.
Regards.

On Wed, Dec 24, 2008 at 1:54 AM, Matt Nordhoff
wrote:

> ANURAG BAGARIA wrote:
> > Hello,
> >
> > I am a Python Newbie and would like to call a short python script via
> > browser using a CGI script, but initially I am trying to call the same
> > python script directly through python command line. The script intends
> > to perform a few command line in a pipe and I have written the script (a
> > short one) as follows.
> >
> > #!/usr/bin/python
> >
> > import cgi, string, os, sys, cgitb, commands, subprocess
> > import posixpath, macpath
> > #file = "x.tar.gz"
> > #comd = "tar -xf %s" % (file)
> > #os.system(comd)
> > #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
> > comd = [\
> > "tar -xf x.tar.gz", \
> > "cd demo", \
> > "cp README ../", \
> >   ]
>
> That's not how subprocess.call() works. You're trying to run an
> executable called "tar -xf x.tar.gz", passing it the arguments "cd demo"
> and "cp README ../".
>
> > outFile = os.path.join(os.curdir, "output.log")
> > outptr = file(outFile, "w")
> > errFile = os.path.join(os.curdir, "error.log")
> > errptr = file(errFile, "w")
> > retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> > errptr.close()
> > outptr.close()
> > if not retval == 0:
> > errptr = file(errFile, "r")
> > errData = errptr.read()
> > errptr.close()
> > raise Exception("Error executing command: " + repr(errData))
> >
> >
> > but after trying to execute this independently, I get the following
> > error which I am unable to interpret :
> >
> > Traceback (most recent call last):
> >   File "process.py", line 18, in 
> > retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> >   File "/usr/lib/python2.5/subprocess.py", line 443, in call
> > return Popen(*popenargs, **kwargs).wait()
> >   File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
> > errread, errwrite)
> >   File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
> > raise child_exception
> >
> >
> > Could someone suggest where am I going wrong and if corrected, what is
> > the probability of this script being compatible with being called
> > through the browser. Thanking you people in advance.
>
> Well, you'd need to output something, but otherwise, sure, why not?
>
> print "Content-Type: text/html"
> print
> print "..."
>
> > Regards.
>
> Why do you even need to use subprocess to do this? All it's doing is
> extracting the README file from a tarball, right? You can use the
> tarfile module for that.
>
> 
> --
>



-- 
I just want to LIVE while I'm alive.


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


Re: using subprocess module in Python CGI

2008-12-23 Thread Matt Nordhoff
ANURAG BAGARIA wrote:
> Hello,
> 
> I am a Python Newbie and would like to call a short python script via
> browser using a CGI script, but initially I am trying to call the same
> python script directly through python command line. The script intends
> to perform a few command line in a pipe and I have written the script (a
> short one) as follows.
> 
> #!/usr/bin/python
> 
> import cgi, string, os, sys, cgitb, commands, subprocess
> import posixpath, macpath
> #file = "x.tar.gz"
> #comd = "tar -xf %s" % (file)
> #os.system(comd)
> #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
> comd = [\
> "tar -xf x.tar.gz", \
> "cd demo", \
> "cp README ../", \
>   ]

That's not how subprocess.call() works. You're trying to run an
executable called "tar -xf x.tar.gz", passing it the arguments "cd demo"
and "cp README ../".

> outFile = os.path.join(os.curdir, "output.log")
> outptr = file(outFile, "w")
> errFile = os.path.join(os.curdir, "error.log")
> errptr = file(errFile, "w")
> retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> errptr.close()
> outptr.close()
> if not retval == 0:
> errptr = file(errFile, "r")
> errData = errptr.read()
> errptr.close()
> raise Exception("Error executing command: " + repr(errData))
> 
> 
> but after trying to execute this independently, I get the following
> error which I am unable to interpret :
> 
> Traceback (most recent call last):
>   File "process.py", line 18, in 
> retval = subprocess.call(comd, 0, None, None, outptr, errptr)
>   File "/usr/lib/python2.5/subprocess.py", line 443, in call
> return Popen(*popenargs, **kwargs).wait()
>   File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
> errread, errwrite)
>   File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
> raise child_exception
> 
> 
> Could someone suggest where am I going wrong and if corrected, what is
> the probability of this script being compatible with being called
> through the browser. Thanking you people in advance.

Well, you'd need to output something, but otherwise, sure, why not?

print "Content-Type: text/html"
print
print "..."

> Regards.

Why do you even need to use subprocess to do this? All it's doing is
extracting the README file from a tarball, right? You can use the
tarfile module for that.


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


Re: using subprocess module in Python CGI

2008-12-23 Thread ANURAG BAGARIA
Thank you for the prompt response.

Yeah, I missed out one line at the end of the error, the whole of which is:

Traceback (most recent call last):
  File "process.py", line 18, in 
retval = subprocess.call(comd, 0, None, None, outptr, errptr)
  File "/usr/lib/python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
  File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Looking forward to any kind of help or suggestion in this regard.
Thanks.

On Tue, Dec 23, 2008 at 7:00 AM, Chris Rebert  wrote:

> On Mon, Dec 22, 2008 at 2:02 AM, ANURAG BAGARIA
>  wrote:
> > Hello,
> >
> > I am a Python Newbie and would like to call a short python script via
> > browser using a CGI script, but initially I am trying to call the same
> > python script directly through python command line. The script intends to
> > perform a few command line in a pipe and I have written the script (a
> short
> > one) as follows.
> >
> > #!/usr/bin/python
> >
> > import cgi, string, os, sys, cgitb, commands, subprocess
> > import posixpath, macpath
> > #file = "x.tar.gz"
> > #comd = "tar -xf %s" % (file)
> > #os.system(comd)
> > #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
> > comd = [\
> > "tar -xf x.tar.gz", \
> > "cd demo", \
> > "cp README ../", \
> >   ]
> > outFile = os.path.join(os.curdir, "output.log")
> > outptr = file(outFile, "w")
> > errFile = os.path.join(os.curdir, "error.log")
> > errptr = file(errFile, "w")
> > retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> > errptr.close()
> > outptr.close()
> > if not retval == 0:
> > errptr = file(errFile, "r")
> > errData = errptr.read()
> > errptr.close()
> > raise Exception("Error executing command: " + repr(errData))
> >
> >
> > but after trying to execute this independently, I get the following error
> > which I am unable to interpret :
> >
> > Traceback (most recent call last):
> >   File "process.py", line 18, in 
> > retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> >   File "/usr/lib/python2.5/subprocess.py", line 443, in call
> > return Popen(*popenargs, **kwargs).wait()
> >   File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
> > errread, errwrite)
> >   File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
> > raise child_exception
>
> There should be at least one more line in this traceback, and that
> line is the most important one.
> People will need that line to help you with your problem.
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...
> http://rebertia.com
>



-- 
I just want to LIVE while I'm alive.


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


Re: using subprocess module in Python CGI

2008-12-22 Thread Chris Rebert
On Mon, Dec 22, 2008 at 2:02 AM, ANURAG BAGARIA
 wrote:
> Hello,
>
> I am a Python Newbie and would like to call a short python script via
> browser using a CGI script, but initially I am trying to call the same
> python script directly through python command line. The script intends to
> perform a few command line in a pipe and I have written the script (a short
> one) as follows.
>
> #!/usr/bin/python
>
> import cgi, string, os, sys, cgitb, commands, subprocess
> import posixpath, macpath
> #file = "x.tar.gz"
> #comd = "tar -xf %s" % (file)
> #os.system(comd)
> #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
> comd = [\
> "tar -xf x.tar.gz", \
> "cd demo", \
> "cp README ../", \
>   ]
> outFile = os.path.join(os.curdir, "output.log")
> outptr = file(outFile, "w")
> errFile = os.path.join(os.curdir, "error.log")
> errptr = file(errFile, "w")
> retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> errptr.close()
> outptr.close()
> if not retval == 0:
> errptr = file(errFile, "r")
> errData = errptr.read()
> errptr.close()
> raise Exception("Error executing command: " + repr(errData))
>
>
> but after trying to execute this independently, I get the following error
> which I am unable to interpret :
>
> Traceback (most recent call last):
>   File "process.py", line 18, in 
> retval = subprocess.call(comd, 0, None, None, outptr, errptr)
>   File "/usr/lib/python2.5/subprocess.py", line 443, in call
> return Popen(*popenargs, **kwargs).wait()
>   File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
> errread, errwrite)
>   File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
> raise child_exception

There should be at least one more line in this traceback, and that
line is the most important one.
People will need that line to help you with your problem.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


using subprocess module in Python CGI

2008-12-22 Thread ANURAG BAGARIA
Hello,

I am a Python Newbie and would like to call a short python script via
browser using a CGI script, but initially I am trying to call the same
python script directly through python command line. The script intends to
perform a few command line in a pipe and I have written the script (a short
one) as follows.

#!/usr/bin/python

import cgi, string, os, sys, cgitb, commands, subprocess
import posixpath, macpath
#file = "x.tar.gz"
#comd = "tar -xf %s" % (file)
#os.system(comd)
#commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
comd = [\
"tar -xf x.tar.gz", \
"cd demo", \
"cp README ../", \
  ]
outFile = os.path.join(os.curdir, "output.log")
outptr = file(outFile, "w")
errFile = os.path.join(os.curdir, "error.log")
errptr = file(errFile, "w")
retval = subprocess.call(comd, 0, None, None, outptr, errptr)
errptr.close()
outptr.close()
if not retval == 0:
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(errData))


but after trying to execute this independently, I get the following error
which I am unable to interpret :

Traceback (most recent call last):
  File "process.py", line 18, in 
retval = subprocess.call(comd, 0, None, None, outptr, errptr)
  File "/usr/lib/python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
  File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child
raise child_exception


Could someone suggest where am I going wrong and if corrected, what is the
probability of this script being compatible with being called through the
browser. Thanking you people in advance.

Regards.

-- 
I just want to LIVE while I'm alive.


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


Permission Issues in python cgi scripts on Apache 2.2 on OSX Leopard

2008-11-14 Thread Dan Yamins
Using Apache 2.2 on my local OSX machine, I;ve set up a virtual host to
serve a directory that a project of mine is in.  In this directory, I have
some python .cgi scripts that I use to dynamically generated locally-used
html code.   In several places,scripts that work fine when not run as .cgi
scripts via the webserver (but just as regular .py scripts in the Python
interpreter) break when run by Apache because of what look like permissions
related issues. Specifically:

1) When a script attempts to make a directory, it fails to do so unless
writing is enabled on the superdirectory for all users, not just owner or
group.   I see a "permission denied" error via the cgitb output.

and,

2) Some operating system stat modification functions, like os.utim, fail --
with the error message being that "Operation is Not Permitted".I've put
permissions to 777 for all the involved files but to no avail.   (Am I right
in thinking that this problem is also a permissions issue?  I know the first
one is, because the error message says so explicitly.)

My computer is running off-line and this only ever going to be a local
development task.   So, my basic question is:  is there some way, for the
directories that I'm serving, to turn of all the permissions protections
whatsoever?  E.g. to run my cgi scripts as if the process running the
scripts had all root privileges?  And so that I can run scripts via cgi
without having to worry about problems like the "Operation Not Permitted
Errror"?  (I want to be able to take advantage of using pythong for dynamic
web-page generation without worrying about permission and security issues,
since these files will never be near anything online.)

I've tried to do things like put the proper things in my Apache
configuration files (e.g the virtual host conf fil, the httpd.conf file,
etc...), but this failed to achieve my goal.

I apologize if I'm sending this mail to the wrong list,

Thanks,
Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with running Python CGI Scripts

2008-09-03 Thread Gabriel Genellina
En Wed, 03 Sep 2008 05:29:39 -0300, Edward FISHER <[EMAIL PROTECTED]>  
escribi�:


I can get the script to run the python script but all that happens is  
that the black python box appears then disapears, the html that the  
python scripts should generate is never output.

[...]
This is calling the pyc file of the python script. I dont understand why  
if i call the py file itself all i get returned is the plain text of the  
python file.


That's a server setting (Apache or whatever) - make sure it is configured  
to *execute* the script.



The python script is:

#!/usr/local/bin/python
import cgi

def main():
print "Content-type: text/html\n"


I hope this is just the way you posted your message, but remember that in  
Python indentation is important. The above code isn't valid. Once you are  
sure that your script doesn't have syntax errors, add this lines on the  
top to help debugging:


import cgitb; cgitb.enable()

--
Gabriel Genellina

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

Problems with running Python CGI Scripts

2008-09-03 Thread Edward FISHER
Hey guys.
Im having problems running a python cgi. Im using the example code from:
http://www.python.org/doc/essays/pp...east/sld041.htm as writen by Van Rossum 
himself

I can get the script to run the python script but all that happens is that the 
black python box appears then disapears, the html that the python scripts 
should generate is never output.

My html is:



A Typical HTML form

A Typical HTML form
*Test CGI script and HTML to
test server for correct running of python cgi scripting

Your First Name:

Your Last Name: 
Click here to submit form: 



This is calling the pyc file of the python script. I dont understand why if i 
call the py file itself all i get returned is the plain text of the python file.

The python script is:

#!/usr/local/bin/python
import cgi

def main():
print "Content-type: text/html\n"
form = cgi.FieldStorage()
if form.has_key("firstname") and form["firstname"].value != "":
#if form has an object called firstname and the value is not an empty string
print "Hello", form["firstname"].value, ""
else:
print "Error! Please enter first name."

main()

If you need to see what happens then follow this link:
http://www.fisherphotographics.co.uk/testhtml1.htm

The python file has come directly from the example so i must me doing something 
wrong. I have all the correct permissions etc
Thanks very much
Ed Fisher 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend a blog program written using python-cgi

2008-06-12 Thread Royt
On Jun 12, 4:58 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Royt wrote:
> > Hi, I'm a newbie to Python, but I think it won't be too hard to learn.
> > A few days ago I registered Google App Engine, it only support Python
> > 2.5. I want to set my blog on it soon. But it's not easy for me to
> > finish it in a short time since I'm not very familiar with Python, so
> > I want find some codes available, throught reading the code, I can
> > learn something from it. I know there are many frameworks for web
> > development, but I just want the code using traditional CGI method,
> > it's easy to use and it doesn't require any additional knowledge about
> > framework. I need a simple example (support basic function of a
> > weblog, easy to revise) but not a complicated huge monster (I don't
> > think such a thing now exists).
>
> I guess you are out of luck. Usually people use frameworks because it *does*
> make work easier. AFAIK google engine supports Django. So try & aquaint you
> with that - and I bet there are Django-based blogs out there.
>
> Diez

Oh, I'm out of luck, maybe it means few code of python-cgi blog
exists. So I'd like to find a django blog, sf.net should at least have
a piece of code, I guess. Of course, if someone could tell which
project is sipmle but pragmatic, that's better.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend a blog program written using python-cgi

2008-06-12 Thread Diez B. Roggisch
Royt wrote:

> Hi, I'm a newbie to Python, but I think it won't be too hard to learn.
> A few days ago I registered Google App Engine, it only support Python
> 2.5. I want to set my blog on it soon. But it's not easy for me to
> finish it in a short time since I'm not very familiar with Python, so
> I want find some codes available, throught reading the code, I can
> learn something from it. I know there are many frameworks for web
> development, but I just want the code using traditional CGI method,
> it's easy to use and it doesn't require any additional knowledge about
> framework. I need a simple example (support basic function of a
> weblog, easy to revise) but not a complicated huge monster (I don't
> think such a thing now exists).

I guess you are out of luck. Usually people use frameworks because it *does*
make work easier. AFAIK google engine supports Django. So try & aquaint you
with that - and I bet there are Django-based blogs out there.

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


Please recommend a blog program written using python-cgi

2008-06-12 Thread Royt
Hi, I'm a newbie to Python, but I think it won't be too hard to learn.
A few days ago I registered Google App Engine, it only support Python
2.5. I want to set my blog on it soon. But it's not easy for me to
finish it in a short time since I'm not very familiar with Python, so
I want find some codes available, throught reading the code, I can
learn something from it. I know there are many frameworks for web
development, but I just want the code using traditional CGI method,
it's easy to use and it doesn't require any additional knowledge about
framework. I need a simple example (support basic function of a
weblog, easy to revise) but not a complicated huge monster (I don't
think such a thing now exists).

I find some online course, i.e. 
http://www.upriss.org.uk/python/PythonCourse.html
& http://www.python.org/doc/essays/ppt/sd99east/index.htm  but I
didn't find the code needed, could anyone recommend it to me? thanks.
--
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: argument to python cgi script

2008-04-10 Thread Gabriel Genellina
En Wed, 09 Apr 2008 11:14:33 -0300, syed mehdi <[EMAIL PROTECTED]>  
escribió:

> Hi Guys,
> If someone can help me in telling how can i pass arguments to python cgi
> script then that will be good.
> like if i want to pass "some argument" to my remote python script, by
> calling something like:
> http://localhost/cgi-bin/test.py?some\ argument.
> What is the correct way of sending arguments in this way, and how can i
> decode/receive them in test.py

Encoding:

py> args = {'some': 'argument', 'x': 1, 'z': 23.4}
py> import urllib
py> urllib.urlencode(args)
'x=1&z=23.4&some=argument'

You can then use urllib.urlopen or urllib2.urlopen to send the HTTP  
request and retrieve the response.
http://docs.python.org/lib/module-urllib.html

In the server side, use cgi.FieldStorage:

form = cgi.FieldStorage()
x = form.getfirst('x', 0) # '1'
y = form.getfirst('y', 0) # '0'
z = form.getfirst('z', 0) # '23.4'

http://docs.python.org/lib/module-cgi.html

-- 
Gabriel Genellina

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


argument to python cgi script

2008-04-09 Thread syed mehdi
Hi Guys,
If someone can help me in telling how can i pass arguments to python cgi
script then that will be good.
like if i want to pass "some argument" to my remote python script, by
calling something like:
http://localhost/cgi-bin/test.py?some\ argument.
What is the correct way of sending arguments in this way, and how can i
decode/receive them in test.py

Thanks & Regards
Syed
-- 
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


Python - CGI - XML - XSD

2008-03-11 Thread xkenneth
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?

Regards,
Kenneth Miller
-- 
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


Python CGI & Webpage with an Image

2008-03-05 Thread rodmc
Hi,

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?

Kind regards,

rod
-- 
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


Python CGI script and CSS style sheet

2008-01-23 Thread epsilon
All:

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"
6tag_form = cgi.FieldStorage()
7
8head_open_close = """
9
10 
11 Tag Sheet
12 
13  """
14
15  body_open = """
16  
17  
18  
19"""
20

Thank you,
Christopher
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipes python cgi and gnupg

2008-01-08 Thread alisonken1
On Dec 28 2007, 7:07 pm, [EMAIL PROTECTED] wrote:

> form = cgi.FieldStorage()
> if not form.has_key("pass"):
>print "Enter password"
>
> filename = "test.gpg"
> pass = form.getvalue("pass").strip()
> os.system("gpg --version > gpg.out")
> os.system("echo %s | gpg --batch --password-fd 0 --decrypt %s > d.out"
> %(pass,filename))

The last time I checked, "pass" is a reserved word in Python.

Since you are using a reserved word as a variable, maybe that's what's
messing with your output?
-- 
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


Python CGI - Presenting a zip file to user

2008-01-02 Thread jwwest
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
-- 
http://mail.python.org/mailman/listinfo/python-list


pipes python cgi and gnupg

2007-12-28 Thread byte8bits
I think this is more a GnuPG issue than a Python issue, but I wanted
to post it here as well in case others could offer suggestions:

I can do this from a python cgi script from a browser:

os.system("gpg --version > gpg.out")

However, I cannot do this from a browser:

os.system("echo %s | gpg --batch --password-fd 0 -d %s > d.out"
%(pass, filename))

The output file is produced, but it's zero byte. I want the decrypted
file's content, but the pipe seems to mess things up. The script works
fine when executed from command line. The output file is produced as
expected. When executed by a browser, it does not work as expected...
only produces a zero byte output file. Any tips? I've googled a bit
and experimented for a few nights, still no go.

Thanks,
Brad

Here's the entire script:

#!/usr/local/bin/python

import cgi
import cgitb; cgitb.enable()
import os
import tempfile

print "Content-Type: text/html"
print
print "T"
print "H"

form = cgi.FieldStorage()
if not form.has_key("pass"):
   print "Enter password"

filename = "test.gpg"
pass = form.getvalue("pass").strip()
os.system("gpg --version > gpg.out")
os.system("echo %s | gpg --batch --password-fd 0 --decrypt %s > d.out"
%(pass,filename))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically generating temporary files through python/cgi (ot)

2007-11-01 Thread Hendrik van Rooyen


Miss Pfeffe  wrote:


>How do you make a python out of a banana?!

You kiss it just long enough - else it turns into a frog, so be careful!



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


dynamically generating temporary files through python/cgi

2007-10-31 Thread Miss Pfeffe
How do you make a python out of a banana?!-- 
http://mail.python.org/mailman/listinfo/python-list

Streaming files from python cgi

2007-09-27 Thread Salil Kulkarni
Hello,

I am trying to create a cgi which downloads a pdf/tiff file from an
ftpserver using ftplib.
Everything works until this point.
But, once the file has been retrieved, I want to be able to stream the file
to the browser so that the user gets an option to save it, or open it with
the necessary application. However, I am not able to figure out how this can
be done.

The code looks as follows:

 #!/usr/local/python2.1/bin/python

 import Path, cgi, sys, os
 from ftplib import FTP
 print "content-type: application/pdf\n\n"

  ftp = FTP("hostname", "salil", "passwd")

  try:
  ftp.cwd("/home/salil")
  except:
  print "Could change directory on remote server"
  sys.exit(1)


  f = open("temp.pdf", "w")
  ftp.retrbinary("RETR O_F.pdf", f.write)
  f.close()
  f = open("temp.pdf", "r")
 print f.read()


I am using Apache 1.3 for this cgi. It would be great if someone can point
out how this can be accomplished, or if there are any examples out there
which I can refer to.

Thanks,
Salil.
-- 
http://mail.python.org/mailman/listinfo/python-list

My first Python CGI (was: Coming from Perl)

2007-09-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Amer Neely  <[EMAIL PROTECTED]> wrote:
>Amer Neely wrote:
>> TheFlyingDutchman wrote:
>>> On Sep 12, 5:30 pm, Amer Neely <[EMAIL PROTECTED]> wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 -- 
 Amer Neely
 w:www.webmechanic.softouch.on.ca/
 Perl | MySQL programming for all data entry forms.
 "Others make web sites. We make web sites work!"
>>>
>>> I am not sure if this is what you are looking for, but Python has a
>>> special string with 3 quotes that I believe duplicates part of the
>>> functionality of a here document:
>>>
>>> myHmtlHeader = """
>>> 
>>> My Page
>>> 
>>> """
>>>
>>> print myHtmlHeader
>>>
>>>
>>> outputs:
>>>
>>>
>>> 
>>> My Page
>>> 
>>>
>> 
>> Well, I have checked everything I can but I'm getting '500 Internal 
>> Server Error'. The log files aren't helpful:
>> [Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
>> of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py
>> 
>> I can't even get it to run on my home PC running Apache + Win2K. Same 
>> error.
>> 
>> My script:
>> #!/usr/bin/python
>> import cgitb; cgitb.enable(display=0, logdir=".")
>> import sys
>> sys.stderr = sys.stdout
>> print "Content-Type: text/html"
>> print
>> 
>> print """
>> 
>> 
>> Hello 
>> from Python
>> 
>> Goodbye.
>> 
>> 
>> """
>> 
>
>I should have added that it runs from the command line OK.
.
.
.
Yes, it should work fine.  Do the things you'd do if it were Perl source:
when you say "it runs from the command line OK", do you mean invocation of
/home/softouch/public_html/cgi-bin/scratch/hello.py gives sensible results?
Does your Web server recognize that .py is a CGI extension?  What are the
permissions on /home/softouch/public_html/cgi-bin/scratch/hello.py?

Might your server have an issue with "Content-Type" vs. "Content-type"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python & cgi on win98--tinyweb problems, etc

2007-06-28 Thread Kirk Bailey
RE: TinyWeb running python in windows

PROBLEM: getting python scripts to execute.
SOLUTION: Insure the script ends in the name extension .py.

Windows associates all such files with the pythonw.exe interpreter program, 
and will use it to interpret them. IT IGNORES THE SHEBANG (the first line in 
a script which in the lovely world of un*x points to the interpreter 
program). Some servers have config files to tell the server what to use. 
TinyWeb does not, and relies on windows file associations to direct it to 
the proper interpreter.

Also note that it is possible for windows to conceal name extensions in some 
configurations, and also to create name extensions it does not display, 
resulting in some interesting hair pulling evenings chasing bugs.

Also note that tinyweb checks for the existence of a default page to use if 
none is specified in an incoming request. IF YOU CHANGE THE FILE NAME AFTER 
TINY LOADS IT WILL BARK LIKE A DOG. For instance, index.htm or index.html 
are equally acceptable. You had .htm. then you decided to change it to 
.html- and the server started woofing. It thinks the file index.htm still is 
there someplace and is looking for it! If you change the file name, restart 
the server.

I used tinyweb in supporting the development of windows wiki, and in all 
that crazy alpha stage flakiness, it NOT ONCE blew out. It is BULLETPROOF.

But it is it's own strange beast, and has it's own peculiarities.

-- 
Salute!
-Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

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


Python CGI and Browser timeout

2007-04-26 Thread skulka3
Hello,

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?

Thanks,

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


  1   2   3   >