0
필자는 지금이 python 스크립트를 작성하고 있으며이 오류가 발생했습니다. 나는 압축을 풀려면 다른 값을 가져야한다고 생각하고 있지만, 나는 그 값에 무엇을 넣어야하는지 알고 있지 않습니까? 어떤 도움이라도 대단히 감사하겠습니다.라즈베리 파이 파이썬 ValueError?
ERROR
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()
그래서 더 많은 라인을 원한다는 아이디어가 나에게 왔습니다. 그래서 나는 비밀 파일에 한 줄 밖에 없었다. 그래서 더 많은 이름을 찾고 있는지 테스트하기 위해 더미 라인을 추가했습니다. 그리고 빵! 그것은 효과가 있었다. 가짜 사용자 이름과 암호를 추가 한 후 스크립트가 완벽하게 실행되었습니다. – Celerium