Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.5.1&;fdb 1.5.1-0x00175BB0处的fdb.fbcore.Cursor对象_Python_Python 3.x_Firebird_Fdb - Fatal编程技术网

Python 3.5.1&;fdb 1.5.1-0x00175BB0处的fdb.fbcore.Cursor对象

Python 3.5.1&;fdb 1.5.1-0x00175BB0处的fdb.fbcore.Cursor对象,python,python-3.x,firebird,fdb,Python,Python 3.x,Firebird,Fdb,我尝试用Python编写脚本,他: 连接到Firebird数据库 在连接的数据库中执行select 通过选择从数据库重新输出,为每个结果记录发送电子邮件 我使用:WindowsVista x64SP2,Python版本3.5.1,firebird驱动程序FDB1.5.1 使用follow脚本后,我收到电子邮件消息:fdb.fbcore.Cursor对象位于0x00175BB0 请提出建议 # -*- coding:utf-8 -*- import smtplib from email.mi

我尝试用Python编写脚本,他:

  • 连接到Firebird数据库

  • 在连接的数据库中执行select

  • 通过选择从数据库重新输出,为每个结果记录发送电子邮件

我使用:WindowsVista x64SP2,Python版本3.5.1,firebird驱动程序FDB1.5.1

使用follow脚本后,我收到电子邮件消息:fdb.fbcore.Cursor对象位于0x00175BB0

请提出建议

# -*- 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()

您正在打印光标对象,而不是从光标中检索值。
execute
方法返回光标本身(因此
select
cur
是同一个对象)

相反,您需要使用:

cur = con.cursor()
cur.execute("select telephone from person")
message_text = cur.fetchone()

您正在打印游标对象,而不是从游标中检索值。
execute
方法返回光标本身(因此
select
cur
是同一个对象)。