Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Don't Understand Error

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


victorsubervi at gmail

Nov 23, 2009, 10:10 AM

Post #1 of 3 (137 views)
Permalink
Don't Understand Error

Hi;
I have the following code:

#!/usr/bin/env python

import smtplib
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
import MySQLdb
import re, string

def mailSpreadsheet():
user, passwd, db, host = login()
database = MySQLdb.connect(host, user, passwd, db)
cursor= database.cursor()
ourEmail1 = 'anemail [at] here'
ourEmail2 = 'anotheremail [at] here'
form = cgi.FieldStorage()
client = form.getfirst('client', '')
clientEmail = form.getfirst('clientEmail', '')
po = form.getfirst('po', '')
subject = 'Order From Client'
sql = 'select clientEmail from clients where client="%s";' %
(string.replace(client, '_', ' '))
cursor.execute(sql)
clientEmail = cursor.fetchone()[0]
cursor.execute('select * from %s;' % (client))
data = cursor.fetchall()
i = 0
if po != '':
order = 'PO#: %s\n' % (po)
else:
order = ''
total = 0
for row in data:
i += 1
quantity = form.getfirst('order_' + str(i), '')
if quantity != '0':
sql = 'select * from products p join %s c on p.ID=c.ID where c.ID=%s;'
% (client, str(i))
cursor.execute(sql)
stuff = cursor.fetchone()
price = str(int(stuff[5]*100))
price = price[0:len(price)-2] + '.' + price[-2:]
item, price, description, discount = stuff[2], price, stuff[3],
stuff[8]
order += 'Item #: ' + item + '\tQuantity: ' + quantity + '\tPrice: ' +
price + '\tDiscount: ' + str(discount) + '\tDescription: ' +
description[:20] + '...\n'
total += float(price) * int(quantity) * (100 - discount)/100
order += 'TOTAL: $' + str(total)
msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', '
'), order)
session = smtplib.SMTP("localhost")
session.login(user, passwd) # only if it requires auth
header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n"
% subject
# session.sendmail(clientEmail, ourEmail1, header+msg)
session.sendmail(clientEmail, ourEmail2, header+msg)

mailSpreadsheet()

The email does get sent, and it that happens out of the last line of code.
If I surround the code with code to make it print a Web page, it prints
without any error. However, as it is, it throws the following error:

The server encountered an internal error or misconfiguration and was unable
to complete your request.

Please contact the server administrator, me [at] creative and inform them of
the time the error occurred, and anything you might have done that may have
caused the error.

More information about this error may be available in the server error log.

[Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end of
script headers: mailSpreadsheet.py, referer:
http://globalsolutionsgroup.vi/display_spreadsheet.py

Why?

TIA,

Victor


carsten.haese at gmail

Nov 23, 2009, 12:18 PM

Post #2 of 3 (113 views)
Permalink
Re: Don't Understand Error [In reply to]

Victor Subervi wrote:
> [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end
> of script headers: mailSpreadsheet.py, referer:
> http://globalsolutionsgroup.vi/display_spreadsheet.py
>
> Why?

A CGI script is expected to produce output. Your script doesn't produce
any output, and Apache is complaining about that.

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 23, 2009, 12:33 PM

Post #3 of 3 (114 views)
Permalink
Re: Don't Understand Error [In reply to]

On Mon, Nov 23, 2009 at 3:18 PM, Carsten Haese <carsten.haese [at] gmail>wrote:

> Victor Subervi wrote:
> > [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end
> > of script headers: mailSpreadsheet.py, referer:
> > http://globalsolutionsgroup.vi/display_spreadsheet.py
> >
> > Why?
>
> A CGI script is expected to produce output. Your script doesn't produce
> any output, and Apache is complaining about that.
>

Thank you.
V

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.