Raspberry Pi Python ValueError吗?

芹菜

我已经写了一段时间的这个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()
乔纳森·莱因哈特(Jonathon Reinhart)
  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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Python Raspberry Pi GPIO错误

来自分类Dev

Raspberry Pi可以运行Ubuntu吗?

来自分类Dev

Dart可用于Raspberry Pi吗?

来自分类Dev

在sudo关闭后启动Raspberry Pi吗?

来自分类Dev

Raspberry Pi可以运行Ubuntu吗?

来自分类Dev

Dart可用于Raspberry Pi吗?

来自分类Dev

Raspberry PI可以捕获HDMI输入吗

来自分类Dev

从Shell脚本(Raspberry Pi)运行Chromium吗?

来自分类Dev

我应该买Raspberry Pi吗?

来自分类Dev

我必须购买 Raspberry Pi 设备吗?

来自分类Dev

将WebApp部署到Raspberry Pi时使用Python Virtualenv吗?

来自分类Dev

程序与Raspberry Pi 3兼容但与Pi Zero不兼容吗?

来自分类Dev

Raspberry Pi闪烁的LED问题-Python与Java

来自分类Dev

Raspberry Pi Camera自动捕获python脚本

来自分类Dev

Raspberry Pi Python脚本未定义?

来自分类Dev

python + raspberry pi gpio无效语法

来自分类Dev

是否安装了Python:(Raspberry Pi Ubuntu)

来自分类Dev

Raspberry Pi Zero上的Python非法指令

来自分类Dev

处于 Sl 状态的 Raspberry Pi python 脚本

来自分类Dev

Raspberry Pi 之间的 Python 套接字连接

来自分类Dev

我可以在Raspberry Pi 4上使用.NET SIMD吗?

来自分类Dev

我可以在Raspberry Pi 4上使用.NET SIMD吗?

来自分类Dev

安全性:Raspberry Pi真的是无状态的吗?

来自分类Dev

我可以在Raspberry Pi上运行mythbackend吗?

来自分类Dev

我可以在Raspberry Pi上使用Ubuntu One吗?

来自分类Dev

在Raspberry PI上的Python中执行FFmpeg命令

来自分类Dev

Raspberry Pi的Python脚本无法正常运行

来自分类Dev

在Python 2.7.3 / Raspberry Pi中使用特殊字符转义HTML

来自分类Dev

Python / Raspberry Pi关于中断响应时间的保证