1

I try wrote script in Python, who:

  • connect to Firebird database

  • execute select in connected database

  • send e-mail for each one result record from database rerutn by SELECT.

I use: Windows Vista x64 SP2, Python version 3.5.1, firebird driver fdb 1.5.1.

After using follow script I receive e-mail message: fdb.fbcore.Cursor object at 0x00175BB0

Please suggestions.

# -*- coding:utf-8 -*-

import smtplib
from email.mime.text import MIMEText

import fdb 
con = fdb.connect(host='127.0.0.1', database='test', user='SYSDBA', password='masterkey', charset='WIN1250')

to = ['xxxxxx@xxxxxx']
cc = ['xxxxxx@xxxxxx']
bcc = ['xxxxxx@xxxxxx']
from_addr = 'xxxxxx@xxxxxx'
message_subject = "Say Hello"

cur = con.cursor()
select = cur.execute("select telephone from person")
#message_text = "%a" % (select)
message_text = (select)

message = "From: %s\r\n" % from_addr \
        + "To: %s\r\n" % ",".join(to) \
        + "CC: %s\r\n" % ",".join(cc) \
        + "BCC: %s\r\n" % ",".join(bcc) \
        + "Subject: %s\r\n" % message_subject \
        + str(message_text)
to_addrs = to + cc + bcc
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('xxxxxx','xxxxxx')
#server.set_debuglevel(1)

#for message_text in cur.fetchall():
#   print(message_text)

for message_text in cur.fetchall():
    server.sendmail(from_addr, to_addrs, message)

server.quit()
con.close()
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    You are printing the cursor object instead of **retrieving** a value from the cursor. The `execute` method returns the cursor itself (so `select` and `cur` are the same object). – Mark Rotteveel Mar 27 '16 at 10:20

1 Answers1

1

You are printing the cursor object instead of retrieving a value from the cursor. The execute method returns the cursor itself (so select and cur are the same object).

Instead you need to use:

cur = con.cursor()
cur.execute("select telephone from person")
message_text = cur.fetchone()
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197