473,287 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Trying to write CGI script with python...


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
7 1847
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Werner Merkl | last post by:
Hi, Python is really great, for small to big programs. For my colleagues and some circumstances I sometimes need to "compile" a script using py2exe. Cause I use Windows, I like to use the...
3
by: Ali | last post by:
I have the following webpage with a javasctript in it: <html> <head> <title>Custom Objects Test</title> <script language="javascript"> function PrintCard() { line1 = "<hr>\n"; line2 =...
8
by: Greg Brant | last post by:
my script is document.write("<!-- #include virtual\"http://www.where-ever.com/whatevere.html\" -->") but in the html (view source) i get ---------------------------------------------------...
4
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that...
3
by: Matthew Warren | last post by:
I have the following piece of code, taken from a bigger module, that even as I was writing I _knew_ there were better ways of doing it, using a parser or somesuch at least, but learning how wasn't...
34
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas...
2
by: Viewer T. | last post by:
I am trying to write a script that deletes certain files based on certain criteria. What I am trying to do is to automate the process of deleting certain malware files that disguise themselves...
0
by: atulsharma84 | last post by:
i want to write a python script for a device NGX-5500 whose vendor is telllabs i hv to write python file like some other device file i m giving u example here below import java.lang as lang...
5
by: walterbyrd | last post by:
I don't know much php either, but running a php app seems straight forward enough. Python seems to always use some sort of development environment vs production environment scheme. For...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.