Shoutbox

cgi generate a zip file - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: cgi generate a zip file (/showthread.php?tid=90316)

cgi generate a zip file by Jarrod on 04-23-2009 at 11:23 AM

I have some zip generating python saved as a cgi, but the server fails to execute it

quote:
Originally posted by Apache log file
[Thu Apr 23 21:09:21 2009] [error] [client 192.168.1.1] (8)Exec format error: exec of '/Users/alec/Sites/download.cgi' failed
[Thu Apr 23 21:09:21 2009] [error] [client 192.168.1.1] Premature end of script headers: download.cgi

RE: cgi generate a zip file by prashker on 04-23-2009 at 11:31 AM

The code would help :p


RE: cgi generate a zip file by Jarrod on 04-23-2009 at 11:36 AM

python code:
import zipfile,os
ziped = zipfile.ZipFile('project.zip', 'w')
print "Content-Type: text/html"
print
print """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head><body><center>"""
x=os.listdir("./")
for item in x:
    if item!="project.zip":
        ziped.write(item)
print "<br>"*5
print"<a href='project.zip'>Click Here to download the source codes</a>"

print"""
</body>
</html>"""

RE: cgi generate a zip file by prashker on 04-23-2009 at 11:59 AM

Well for one, I see a <center> but no </center>


RE: cgi generate a zip file by Jarrod on 04-23-2009 at 12:10 PM

that won't stop it executing


RE: cgi generate a zip file by -dt- on 04-23-2009 at 12:53 PM

quote:
Originally posted by Jarrod
that won't stop it executing
Try adding

code:
#!/usr/local/bin/python


to the first line of your python file (where the path is the path to python)


http://docs.python.org/library/cgi.html#installin...t-on-a-unix-system
RE: cgi generate a zip file by Jarrod on 04-23-2009 at 10:29 PM

textmate puts that in when I start a new cgi file I just didn't paste it into my post.
textmate does the whole thing correctly as a .py so I'm thinking it's a permissions thing but AFAIK everything is chmod 777