By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Trying to write CGI script with python...

P: n/a

Hi there,

I am new to this so I apologize in advance if I am not following the
right etiquette or something...

I am working on a project for school. My partner has written a
short program in Python which takes 2 arguments - the name of a .mov
file and a number which represents the number of seconds into that
movie. The program then passes this info to MPlayer and produces as
output a .jpg image which is basically the frame of the movie at the
stated time.

It's my job to make this a web-based function, and when I try to
convert my partner's code to a working CGI script, it fails.
Basically, MPlayer is not being accessed properly.

Does anyone have any insight or has anyone tried to do something
similar? I am fairly new to all this...

Thank you!

Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Probably going to need more information about how mplayer is not being
accessed correctly.

CGI uses the shell environment to pass web information to a program...
so maybe this is messing up mplayer. You'll need to augment or wrap
your partners program in order to give you more information about
what's failing (e.g. wrap the call to mplayer in a try/except use the
traceback module to format a traceback if your CGI server is swallowing
it).

Jul 19 '05 #2

P: n/a
If you just want to wrap an existing python script - but pass arguments
from a web interface, it ought to be very easy.

You'll need to understand CGI of course. There's a good free article
about getting started with CGI over at PyZine ( http://www.pyzine.com )
;-)

Can you confirm that your CGI is receiving the arguments correctly ?
How are you calling your partners script ?

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python/cgi.shtml

Jul 19 '05 #3

P: n/a
Just in case you don't have a clue what they are talking about ;)
import traceback
try:
#your stuff here
except:
traceback.print_exc()

That should return any exceptions you may be throwing.

Jul 19 '05 #4

P: n/a
I found an excellent example that was posted by the F-bot.
Fredrik Lundh May 26 2000
From: "Fredrik Lundh" <fred...@pythonware.com>
Date: 2000/05/26

richard_chamberl...@ wrote:
I'm having great difficulties getting Python to work via CGI. Is there anyway I can get the traceback on to the web page so I know what's happening?
the easiest way is to split your CGI module in two parts; use the
following
script as a wrapper, and place the program logic in a separate script
("my-
script.main()" in this case):

#!/usr/bin/env python

import cgi, StringIO, sys, traceback

try:
import myscript
myscript.main()
except:
print "Content-Type:", "text/html"
print
file = StringIO.StringIO()
traceback.print_exc(file=file)
print "<pre>"
print cgi.escape(file.getvalue())
print "</pre>"
I haven't got access to error logs so I can't look at it that way.


</F>

Jul 19 '05 #5

P: n/a
M.E.Farmer wrote:
I found an excellent example that was posted by the F-bot. [...] try:
import myscript
myscript.main()
except:
print "Content-Type:", "text/html"
print
file = StringIO.StringIO()
Note: it's usually a very bad idea to name -anything- "file" unless you
intentionally want to clobber the name of the built-in file object.
traceback.print_exc(file=file)
print "<pre>"
print cgi.escape(file.getvalue())
print "</pre>"
I haven't got access to error logs so I can't look at it that way.


</F>


Jul 19 '05 #6

P: n/a
Jason Mobarak wrote:
M.E.Farmer wrote:
I found an excellent example that was posted by the F-bot.


[...]
try:
import myscript
myscript.main()
except:
print "Content-Type:", "text/html"
print
file = StringIO.StringIO()

Note: it's usually a very bad idea to name -anything- "file" unless you
intentionally want to clobber the name of the built-in file object.

[...]
In fairness to the effbot I feel duty bound to suggest that the example
may have been produced before file() was a built-in function. The effbot
is usually reiable on programming matters.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #7

P: n/a
M.E.Farmer wrote:
I found an excellent example that was posted by the F-bot.
Fredrik Lundh************May*26*2000


Python has since grown the cgitb module. Putting

import cgitb; cgitb.enable()

at the top of your cgi script may be even more convenient than using the
Lundhian wrapper.

Peter
Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.