It turns out it is a cgi issue. If I run this code outside of the cgi-bin it runs just fine. The webhosting company I am using allows python cgi code to run, but I might need to check with them about how it works. Does anyone have advice on python cgi vs. psp vs. python web application frameworks? I do plan on getting my head wrapped around writing python in the web application environment but am a bit confused still. Also, wondering how django compares to ruby on rails etc. Sorry, newbie bewilderment....
Noah On 6/22/06, Noah Gift <[EMAIL PROTECTED]> wrote: > Hi, > > I am writing a few different scripts that need to send email > confirmation and I wanted to use smtplib instead of cheating and using > os.system('mail -s "foo"....) Some of the examples I have seen don't > seem to work for me. (Note, I am new to Python and probably doing > something stupid...thanks :) ) Here is one I grabbed > http://effbot.org/librarybook/smtplib.htm > > import smtplib > import string, sys > > HOST = "localhost" > > FROM = "[EMAIL PROTECTED]" > TO = "[EMAIL PROTECTED]" > > SUBJECT = "for your information!" > > BODY = "next week: how to fling an otter" > > body = string.join(( > "From: %s" % FROM, > "To: %s" % TO, > "Subject: %s" % SUBJECT, > "", > BODY), "\r\n") > > print body > > server = smtplib.SMTP(HOST) > server.sendmail(FROM, [TO], body) > server.quit() > > If I change this to suit my needs it looks like this: > > #!/usr/bin/python > import smtplib > import string, sys > > HOST = "localhost" > > FROM = "[EMAIL PROTECTED]" > TO = "[EMAIL PROTECTED]" > > SUBJECT = "for your information!" > > BODY = "next week: how to fling an otter" > > body = string.join(( > "From: %s" % FROM, > "To: %s" % TO, > "Subject: %s" % SUBJECT, > "", > BODY), "\r\n") > > print body > > server = smtplib.SMTP(HOST) > server.sendmail(FROM, [TO], body) > server.quit() > > When I run it I get this: > > Traceback (most recent call last): > File "./3mail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.3/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > File "/usr/lib64/python2.3/email/base64MIME.py", line 28, in ? > from email.Utils import fix_eols > File "/usr/lib64/python2.3/email/Utils.py", line 10, in ? > import random > File "/usr/lib64/python2.3/random.py", line 818, in ? > _inst = Random() > File "/usr/lib64/python2.3/random.py", line 87, in __init__ > self.seed(x) > File "/usr/lib64/python2.3/random.py", line 100, in seed > a = long(time.time() * 256) # use fractional seconds > TypeError: 'module' object is not callable > -- http://mail.python.org/mailman/listinfo/python-list