我已经写了一段时间的这个python脚本,我只是遇到了这个错误。我以为我需要释放另一个价值,但我不知道我应该在其中赋予什么价值?任何帮助将不胜感激。
错误
File "door_controllerTEST_V4_RFID.py", line 101, in <module>
main()
File "door_controllerTEST_V4_RFID.py", line 94, in main
authenticator = RfidFileAuthenticator()
File "door_controllerTEST_V4_RFID.py", line 73, in __init__
self.readFile()
File "door_controllerTEST_V4_RFID.py", line 80, in readFile
id, tag = line.split(',')
ValueError: need more than 1 value to unpack
脚本
#!/usr/bin/env python3
"""Door Lock: System to control an electric lock"""
import piface.pfio as piface
import piface.pfio as pfio
from time import sleep
pfio.init()
class AuthToken:
def __init__(self, id, secret):
self.id=id
self.secret=secret
class DoorControllerPiFace:
def send_open_pulse(self):
piface.digital_write(0,1)
sleep(5)
piface.digital_write(0,0)
class RfidInput:
def getInput(self):
print "waiting for tag"
tag = raw_input()
return AuthToken(None,tag)
class RfidFileAuthenticator:
filename = "tags.txt"
tags = dict()
def __init__(self):
self.readFile()
def readFile(self):
secrets = open(self.filename, 'r')
print "reading from " + self.filename + " file"
for line in secrets:
line = line.rstrip('\n')
id, tag = line.split(',')
self.tags[tag] = id
def check(self,token):
print "checking if " + token.secret + " is valid"
if token.secret in self.tags:
print "tag found belonging to: " + self.tags[token.secret]
return True
else: "tag not found"
print
return False
def main():
authInput = RfidInput()
authenticator = RfidFileAuthenticator()
doorController = DoorControllerPiFace()
if(authenticator.check(authInput.getInput())):
doorController.send_open_pulse()
if __name__ == '__main__':
main()
File "door_controllerTEST_V4_RFID.py", line 80, in readFile
id, tag = line.split(',')
ValueError: need more than 1 value to unpack
最有可能line
不包含逗号。结果,.split(',')
仅返回了一个字符串,因此无法将其解压缩为两个所需的变量。
出于调试目的,print line
在尝试拆分之前,请先查看其中是否包含预期的信息。如果不是,则应向后工作以尝试查看意外值的来源。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句