我使用版本2.6 for XBMC媒体应用程序处理我的python脚本。
我的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<--
答案 0 :(得分: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)