O'Reilly Forums: P302 Adding A Time - O'Reilly Forums
Page 1 of 1
P302 Adding A Time
#1
Posted 08 February 2012 - 07:26 AM
Hello...
I can run the server ok and open
http://localhost:808...in/test_form.py
but when I enter a time and click "send", it does not process and move to the form that says "OK". My code is here:
import cgi
import os
import time
import sys
import yate
print(yate.start_response('text/plain'))
addr = os.environ['REMOTE_ADDR']
host = os.environ['REMOTE_HOST']
method = os.environ['REQUEST_METHOD']
cur_time = time.asctime(time.localtime())
print(host + ", " + addr + ", " + cur_time + ": " + method + ": ", end='', file = sys.stderr)
form = cgi.FieldStorage()
for each_form_item in form.keys():
print(each_form_item + '->' + form[each_form_item].value, end=' ', file = sys.stderr)
print(file = sys.stderr)
print('OK.')
I can run the server ok and open
http://localhost:808...in/test_form.py
but when I enter a time and click "send", it does not process and move to the form that says "OK". My code is here:
import cgi
import os
import time
import sys
import yate
print(yate.start_response('text/plain'))
addr = os.environ['REMOTE_ADDR']
host = os.environ['REMOTE_HOST']
method = os.environ['REQUEST_METHOD']
cur_time = time.asctime(time.localtime())
print(host + ", " + addr + ", " + cur_time + ": " + method + ": ", end='', file = sys.stderr)
form = cgi.FieldStorage()
for each_form_item in form.keys():
print(each_form_item + '->' + form[each_form_item].value, end=' ', file = sys.stderr)
print(file = sys.stderr)
print('OK.')
#2
Posted 08 February 2012 - 12:30 PM
What platform are you running on: Windows, Mac OS X or Linux? On my Mac OS X and Linux systems, your code is running fine in that I'm seeing the "OK." message in my browser as per the Test Drive on page 303.
--Paul.
--Paul.
#4
Posted 08 February 2012 - 12:55 PM
Just ran your code under Python 3.2 on Windows 7... and it gives me the same results as the other platforms. The "OK." message appears in the browser and the custom status message appears in the console window that's running simple_httpd.py. Just a thought, but... are you running this code under Python 3 or Python 2? It requires 3.
--Paul.
P.S. Add these two lines of code directly under your "import cgi" line. These will direct most server errors to your browser and let you see them:
import cgitb
cgitb.enable()
This technique is discussed on page 248 (Chapter 7).
--Paul.
P.S. Add these two lines of code directly under your "import cgi" line. These will direct most server errors to your browser and let you see them:
import cgitb
cgitb.enable()
This technique is discussed on page 248 (Chapter 7).
#5
Posted 08 February 2012 - 01:12 PM
I am running it on python 3.1.4
That would work if pressing send sent it to another screen. But pressing send does nothing, so no errors show up.
The server command says "cgi script exited successfully".
That would work if pressing send sent it to another screen. But pressing send does nothing, so no errors show up.
The server command says "cgi script exited successfully".
#6
Posted 08 February 2012 - 01:24 PM
Yikes! I'm running out of suggestions... :-(
Can you confirm for me that the FORM that your code generates *before* you click on the send button is the same as the one shown on page 299? Be sure to confirm that the HTML "view source" is exactly as shown at the bottom of that page. This HTML is created by the test_form.py program.
I'm wondering if the correct CGI script is being called... check the value assigned to the ACTION tag in your HTML form. I'm clutching at straws here a little bit (and trying not to insult your intelligence by pointing out really obvious stuff) but I'm really scratching my head what with your code working on all of my machines...
--Paul.
Can you confirm for me that the FORM that your code generates *before* you click on the send button is the same as the one shown on page 299? Be sure to confirm that the HTML "view source" is exactly as shown at the bottom of that page. This HTML is created by the test_form.py program.
I'm wondering if the correct CGI script is being called... check the value assigned to the ACTION tag in your HTML form. I'm clutching at straws here a little bit (and trying not to insult your intelligence by pointing out really obvious stuff) but I'm really scratching my head what with your code working on all of my machines...
--Paul.
#7
Posted 08 February 2012 - 01:40 PM
The cgi script being called is the add_timing_data one.
but maybe my yate code is wrong or something, here is the code for the 2 added functions to yate, if these are correct, I will just keep checking other things....
def create_inputs(inputs_list):
html_inputs = ''
for each_input in inputs_list:
html_inputs = html_inputs + '<input type="Text" name="' + each_input + '" size=40>'
return(html_inputs)
def do_form(name, the_inputs, method="POST", text="Submit"):
with open('templates/form.html') as formf:
form_text = formf.read()
inputs = create_inputs(the_inputs)
form = Template(form_text)
return(form.substitute(cgi_name=name,
http_method=method,
list_of_inputs=inputs,
submit_text=text))
but maybe my yate code is wrong or something, here is the code for the 2 added functions to yate, if these are correct, I will just keep checking other things....
def create_inputs(inputs_list):
html_inputs = ''
for each_input in inputs_list:
html_inputs = html_inputs + '<input type="Text" name="' + each_input + '" size=40>'
return(html_inputs)
def do_form(name, the_inputs, method="POST", text="Submit"):
with open('templates/form.html') as formf:
form_text = formf.read()
inputs = create_inputs(the_inputs)
form = Template(form_text)
return(form.substitute(cgi_name=name,
http_method=method,
list_of_inputs=inputs,
submit_text=text))
paulbarry, on 08 February 2012 - 01:24 PM, said:
Yikes! I'm running out of suggestions... :-(
Can you confirm for me that the FORM that your code generates *before* you click on the send button is the same as the one shown on page 299? Be sure to confirm that the HTML "view source" is exactly as shown at the bottom of that page. This HTML is created by the test_form.py program.
I'm wondering if the correct CGI script is being called... check the value assigned to the ACTION tag in your HTML form. I'm clutching at straws here a little bit (and trying not to insult your intelligence by pointing out really obvious stuff) but I'm really scratching my head what with your code working on all of my machines...
--Paul.
Can you confirm for me that the FORM that your code generates *before* you click on the send button is the same as the one shown on page 299? Be sure to confirm that the HTML "view source" is exactly as shown at the bottom of that page. This HTML is created by the test_form.py program.
I'm wondering if the correct CGI script is being called... check the value assigned to the ACTION tag in your HTML form. I'm clutching at straws here a little bit (and trying not to insult your intelligence by pointing out really obvious stuff) but I'm really scratching my head what with your code working on all of my machines...
--Paul.
#8
Posted 08 February 2012 - 02:09 PM
Grab the complete webapp code for chapter 9 from here:
http://paulbarry.itc...pp-chapter9.zip
Unzip it and compare it to your code. If nothing else, it will let you run the chapter's examples (hopefully) without any errors.
--Paul.
http://paulbarry.itc...pp-chapter9.zip
Unzip it and compare it to your code. If nothing else, it will let you run the chapter's examples (hopefully) without any errors.
--Paul.
#9
Posted 08 February 2012 - 07:20 PM
THANK YOU, IT WORKS FINALLY WITH THE CODE FROM YOUR LINK.
I HATE TO JUST COPY CODE, BUT I AM STILL LEARNING HOW TO PROGRAM AND I JUST LIKE TO SEE IT WORK.
I HATE TO JUST COPY CODE, BUT I AM STILL LEARNING HOW TO PROGRAM AND I JUST LIKE TO SEE IT WORK.
paulbarry, on 08 February 2012 - 02:09 PM, said:
Grab the complete webapp code for chapter 9 from here:
http://paulbarry.itc...pp-chapter9.zip
Unzip it and compare it to your code. If nothing else, it will let you run the chapter's examples (hopefully) without any errors.
--Paul.
http://paulbarry.itc...pp-chapter9.zip
Unzip it and compare it to your code. If nothing else, it will let you run the chapter's examples (hopefully) without any errors.
--Paul.
Share this topic:
Page 1 of 1


















