Sqlite3:InterfaceError:绑定参数错误2 - 可能是不支持的类型

时间:2016-01-23 12:21:57

标签: python sqlite raspberry-pi2

c.execute("INSERT INTO sensors values(?,?,?)",
((format(datetime.now().strftime('%d-%m-%Y %H:%M:%S')),
 pydata['id'], pydata['data'])))

输出:

$ python filterUDPListen.py 
Time: 23-01-2016 12:59:13 Device: AA Data: TEMP017.9
Traceback (most recent call last):
File "filterUDPListen.py", line 71, in <module>
c.execute("INSERT INTO sensors values(?,?,?)",((datetime.now().strftime('%d-%m-%Y %H:%M:%S')), pydata['id'], pydata['data']))
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.

我在更改此代码时遇到了不同的错误。任何人都可以指出我正确的方向摆脱这里的错误吗?

总代码:

while True:
data, addr = sock.recvfrom(1024*8)
pydata = json.loads(data)
if pydata['type'] == 'WirelessMessage':
    if len(sys.argv) == 3:
        if pydata['network'] != sys.argv[2]:
            continue
    if len(sys.argv) >= 2:
        if pydata['id'] == sys.argv[1]:
    now = time()
            timediff = now - lasttime
    lasttime = now
            print("Device: {} Data: {} Time: {} Network: {} Timesince: {}".format(pydata['id'], pydata['data'][0], pydata['timestamp'], pydata['network'], timediff))
    else:
        print("Time: {} Device: {} Data: {}".format (datetime.now().strftime('%d-%m-%Y %H:%M:%S'), pydata['id'], pydata['data'][0]))
        c.execute("INSERT INTO sensors values(?,?,?)",((format(datetime.now().strftime('%d-%m-%Y %H:%M:%S')), pydata['id'], pydata['data'])))
        conn.commit()
        conn.close()

由于

1 个答案:

答案 0 :(得分:0)

while True:
data, addr = sock.recvfrom(1024*8)
pydata = json.loads(data)
if pydata['type'] == 'WirelessMessage':
    if len(sys.argv) == 3:
        if pydata['network'] != sys.argv[2]:
            continue
    if "AWAKE" in (pydata['data'][0]):
        print "Awake"
    elif "SLEEPING" in (pydata['data'][0]):
        print "Sleeping"
    elif "BATT" in (pydata['data'][0]):
        print "Found 'is' in the string."
        temp = pydata['data'][0]
        date_mmddyyyy = strftime("%d %b %Y %H:%M:%S +0000", gmtime())
        temperature_location = pydata['id']
        data = {'date': date_mmddyyyy, 'value': temp}
        result = requests.put(firebase_url + '/' + temperature_location + '/BattLevel.json',data=json.dumps(data))
        print 'Record inserted. Result Code = ' + str(result.status_code) + ',' + result.text
    else:
        temp = pydata['data'][0]
        temperature = temp.replace("TEMP", "")
        date_mmddyyyy = strftime("%d %b %Y %H:%M:%S +0000", gmtime())
        temperature_location = pydata['id']
        data = {'date': date_mmddyyyy, 'value': temperature}
        result = requests.post(firebase_url + '/' + temperature_location + '/temperature.json',
                               data=json.dumps(data))
        print 'Record inserted. Result Code = ' + str(result.status_code) + ',' + result.text
        print (pydata['data'][0])

我最终得到了这一切,现在一切正常。 首先为变量添加时间。