473,698 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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,


Jul 19 '05 #3
Just in case you don't have a clue what they are talking about ;)
import traceback
#your stuff here
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...@python ware.com>
Date: 2000/05/26

richard_chamber l...@ 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
script as a wrapper, and place the program logic in a separate script
script.main()" in this case):

#!/usr/bin/env python

import cgi, StringIO, sys, traceback

import myscript
print "Content-Type:", "text/html"
file = StringIO.String IO()
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.


Jul 19 '05 #5
M.E.Farmer wrote:
I found an excellent example that was posted by the F-bot. [...] try:
import myscript
print "Content-Type:", "text/html"
file = StringIO.String IO()
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.


Jul 19 '05 #6
Jason Mobarak wrote:
M.E.Farmer wrote:
I found an excellent example that was posted by the F-bot.

import myscript
print "Content-Type:", "text/html"
file = StringIO.String IO()

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.

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.

Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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 (Windows) ability, to add some version infos, comments, etc to the exe file. If I use explorer to check, these properties are visible and correct.
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 = "<b>Name: </b>" + this.name + "<br>\n"; line3 = "<b>Email: </b>" + this.email + "<br>\n";
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 --------------------------------------------------- <script language="Javascript" type="text/Javascript"> document.write("\
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 includes the following source: <script language="JavaScript1.2"
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 as fun as coding it... And yes alarm bells went off when I found myself typing eval(), and I'm sure this is an 'unusual' use of for: else: . And I know it's not very robust. As an ex cuse/planation, this is what happens when you get an idea in...
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 .jar packages. A jar file contains all the program files and you can execute the program with java -jar program.jar I am sort of hoping python has something like this because I feel it
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 as system files and hidden files. When I use os.remove() after importing the os module is raises a Windows Error: Access denied probably because the files have disguised themselves as system files. Is there anway to get adequate privileges under...
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 import java.util as util import com.visionael.DataCollection.TL1Dim as TL1Dim import com.visionael.DataCollection.util.VProperties as VProperties import com.visionael.DataCollection.util.VListMap as VListMap from BaseFamily import *
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 development, you are supposed to run a local browser and load - or something like that. Then to run the same thing in a development environment, I have to configure some files, or touch all the files, restart the web-server, or something....
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.