Trouble with CGI code from Code Example 7.3 of the "Python Interactive CGI Tutorial"
Hey gang! I'm having trouble with this script from a CGI lesson I'm working and I can't seem to figure it out. I was wondering if someone could tell me what is wrong. I've spent several hours trying to debug, but no success. Any help would be appreciated. Thank you, Christopher + Python Interactive CGI Tutorial - Code Example 7.3 http://www.cs.virginia.edu/~lab2q/lesson_7/ # Define function display_page. def display_page(result, id, session_key = 0): print "\n" print "\n" print "\tInfo Form\n" print "\n" print "\n" if (result == "passed"): if (session_key == 0): session_key = create_session(id) print id, , you are logged in with key:", session_key, "\n" print "\t\t\n" print "\t\t\n" print "\t\t\n" print "\t\t\n" print "\t\t\n" print "\t\t\n" print "\t\t\n" else: print "You entered the incorrect combo.\n" print "\n" print "\n" -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with CGI code from Code Example 7.3 of the "Python Interactive CGI Tutorial"
Gabriel, Thanks a bunch for your time! That took care of it. Christopher Gabriel Genellina wrote: > On 21 ago, 11:14, epsilon <[EMAIL PROTECTED]> wrote: > > > I'm having trouble with this script from a CGI lesson I'm working and > > I can't seem to figure it out. I was wondering if someone could tell > > me what is wrong. I've spent several hours trying to debug, but no > > success. Any help would be appreciated. > > Next time try to post the exact error message you get - working > crystall balls are hard to find nowadays :) > Ok, it's a syntax error, perhaps you didn't get a useful response from > the server. > The error is here: > > > if (session_key == 0): > > session_key = create_session(id) > > print id, , you are logged in with key:", session_key, > > That should read: > > print id, "you are logged in with key:", session_key, "\n" > > -- > Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Python CGI script and CSS style sheet
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: Python CGI script and CSS style sheet
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
Decision (if, else) routine is not working as intended with CGI module
All:
I'm running into trouble figuring this one out. It seems that my
decision routine is not working as intended. Does anyone know why my
output continues to utilize the "else" portion of the routine.
Thank you,
Christopher
++
#!/usr/bin/python
import cgi
print "Content-type: text/plain\n"
tag_form = cgi.FieldStorage(keep_blank_values=True)
#if not tag_form.has_key("fse00"):
if tag_form["fse00"] == "":
fse000 = {"fse00": "0"}
tag_form.update(fse000)
print "Printing fse000: ", tag_form["fse00"]
else:
print "Printing fse00: ", tag_form["fse00"]
--
http://mail.python.org/mailman/listinfo/python-list
Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options
All: I've been playing with "Lua" and found something really cool that I'm unable to do in "Python". With "Lua", a script can be compiled to byte code using "luac" and by adding "#!/usr/bin/lua" at the top of the binary, the byte code becomes a single file executable. After I found this trick, I ran back to "Python" to give it a try. Well... it didn't work. Is this possible? There are tools which insert "python" and related modules inside the byte code, but this is not the requirement for this situation. The required solution is to insert "#!/ usr/bin/python" (or some string) at the top of a *.pyc byte code file and run it as standalone executable. I'm excited about the possibility and interested in hearing your thoughts. Thank you, Christopher Smiga -- http://mail.python.org/mailman/listinfo/python-list
Re: Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options
On Jan 14, 5:33 pm, "Martin v. Loewis" wrote:
> > I've been playing with "Lua" and found something really cool that I'm
> > unable to do in "Python". With "Lua", a script can be compiled to byte
> > code using "luac" and by adding "#!/usr/bin/lua" at the top of the
> > binary, the byte code becomes a single file executable. After I found
> > this trick, I ran back to "Python" to give it a try. Well... it
> > didn't work. Is this possible?
>
> In Python, a different approach will work, depending on the operating
> system.
>
> E.g. on Linux, you can use binfmt_misc to make executables out of pyc
> code. Run
>
> import imp,sys,string
> magic = string.join(["\\x%.2x" % ord(c) for c in imp.get_magic()],"")
> reg = ':pyc:M::%s::%s:' % (magic, sys.executable)
> open("/proc/sys/fs/binfmt_misc/register","wb").write(reg)
>
> once on your Linux system (or, rather, at boot time), and all pyc
> files become executable (if the x bit is set).
>
> In Debian, installing the binfmt-support package will do that for
> you.
>
> Do "ls /proc/sys/fs/binfmt_misc/" to see what binary types are
> already supported on your system.
>
> HTH,
> Martin
>
> P.S. The approach you present for Lua indeed does not work for
> Python.
Martin,
This works great! Do you or anyone else have information on how to do
the same thing for Windows and/or Solaris.
Thank you again,
Christopher
--
http://mail.python.org/mailman/listinfo/python-list
Re: Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options
On Jan 15, 8:32 am, schmeii wrote: > On Jan 14, 10:55 pm, epsilon wrote: > > > All: > > > I've been playing with "Lua" and found something really cool that I'm > > unable to do in "Python". With "Lua", a script can be compiled to byte > > code using "luac" and by adding "#!/usr/bin/lua" at the top of the > > binary, the byte code becomes a single file executable. After I found > > this trick, I ran back to "Python" to give it a try. Well... it > > didn't work. Is this possible? > > You can't add a string on top of a pyc file but you can add one in a > zipped file. For an example, seehttp://www.noah.org/wiki/Python_zip_exe All: Thanks again and I'm looking at all the options for different operating system Christopher -- http://mail.python.org/mailman/listinfo/python-list
