python错误 绑定参数0 - 可能不支持的类型
我正在为XBMC媒体应用程序编写一个Python脚本,使用的是2.6版本。
我遇到了一个问题,我的Python脚本出现了一个错误:错误内容是:绑定参数0时出错 - 可能是不支持的类型。
这个错误出现在这一行:
cur.execute('SELECT * FROM programs WHERE channel=? AND start_date <= ? AND stop_date >= ?', [channel, now, now])
以下是代码:
import xbmc
import xbmcgui
import xbmcaddon
import os
import urllib2
import StringIO
import sqlite3
from sqlite3 import dbapi2 as database
from xml.etree import ElementTree
import xml.etree.ElementTree as ET
from UserDict import DictMixin
import datetime
import time
class MyClass(xbmcgui.WindowXML):
def onAction(self, action):
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
if os.path.exists(profilePath):
profilePath = profilePath + 'source.db'
con = database.connect(profilePath)
cur = con.cursor()
cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
con.commit()
con.close
tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
profilePath = profilePath + 'source.db'
con = sqlite3.connect(profilePath)
cur = con.cursor()
channels = OrderedDict()
# Get the loaded data
for channel in tv_elem.findall('channel'):
channel_name = channel.find('display-name').text
for program in channel.findall('programme'):
title = program.find('title').text
start_time = program.get("start")
stop_time = program.get("stop")
cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
con.commit()
print 'Channels store into database are now successfully!'
program = None
now = datetime.datetime.now()
#strCh = '(\'' + '\',\''.join(channelMap.keys()) + '\')'
cur.execute('SELECT * FROM programs WHERE channel=? AND start_date <= ? AND stop_date >= ?', [channel, now, now])
row = cur.fetchone()
if row:
programming = program(row['channel'], row['title'], row['start_date'], row['stop_date'])
cur.close()
这是xbmc的日志:
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'sqlite3.InterfaceError'>
Error Contents: Error binding parameter 0 - probably unsupported type.
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\XBMC\addons\script.tvguide\test.py", line 1682, in onAction
cur.execute('SELECT * FROM programs WHERE channel=? AND start_date <= ? AND stop_date >= ?', [channel, now, now])
InterfaceError: Error binding parameter 0 - probably unsupported type.
-->End of Python script error report<--
1 个回答
0
不要使用下面的代码:
cur.execute('SELECT * FROM programs WHERE channel=? AND start_date <= ? AND stop_date >= ?', [channel, now, now])
试试这个:
inq='SELECT * FROM programs WHERE channel=' + str(channel) + ' AND ' start_date <=' + str(now) + ' AND stop_date >= ' + str(now)
cur.execute (inq)