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 = 'anem...@here.com' ourEmail2 = 'anotherem...@here.com' 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, m...@creative.vi 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
-- http://mail.python.org/mailman/listinfo/python-list