AttributeError:“元组”对象没有属性“ datetime”

时间:2018-06-22 09:47:37

标签: mysql database datetime tuples python-telegram-bot

我是python的初学者。我想从python的MySQL数据库中调用datetime并发送给电报,但出现此错误。

AttributeError:“元组”对象没有属性“ datetime”

代码如下:

 import time
 import random
 import datetime
 import telepot
 import MySQLdb

 from telepot.loop import MessageLoop

 db = MySQLdb.connect(host="127.0.0.1",    # your host, usually localhost
                 user="cowrie",         # your username
                 passwd="12345678",  # your password
                 db="cowrie")        # name of the data base
 cur = db.cursor()

def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']

print 'Command received: %s' % command

elif command == '/time':
    cur.execute('SELECT starttime FROM sessions')   
    for result in cur.fetchall():
            bot.sendMessage(chat_id, result.datetime [0])

MessageLoop(bot, handle).run_as_thread()
print 'Bot ready!'

while 1:
time.sleep(10)

任何见识将不胜感激。

0 个答案:

没有答案