Question

Ive been writing this python script for a while now and i just ran into this error. Im thinking i need to have another value to unpack but I dont know what value im supposed to be putting in there? Any help would be greatly appreciated.

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

Script

#!/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()
Was it helpful?

Solution

  File "door_controllerTEST_V4_RFID.py", line 80, in readFile
    id, tag = line.split(',')

ValueError: need more than 1 value to unpack

Most likely, line did not contain a comma. As a result, .split(',') only returned one string, so it could not unpack into your two desired variables.

For debugging purposes, print line before you try to split it, to see if it contains the expected information. If not, you should work backwards to try and see where the unexpected value is coming from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top