pimylifeup / MFRC522-python

Library utilized for Pi My Life Up's guide on setting up an RFID RC522 reader.
https://pimylifeup.com/raspberry-pi-rfid-rc522/
GNU Lesser General Public License v3.0
193 stars 170 forks source link

Unicode/8-bit Error #22

Open HitGrubs opened 4 years ago

HitGrubs commented 4 years ago

I've set up a RC522 Card on my pi using this, and hacked together the Read.py and Write.py scripts into a Clone.py script:


#!usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
    print("Scan Card Now")
    id, text = reader.read()
    print("Current ID:")
    print(id)
    print("Place Card for Write, Then Press ENTER")
    input("")
    reader.write(text)
    print("Write Complete")

Which works just fine when testing on blank cards. However, when I tried to clone an old hotel keycard I get:

Traceback (most recent call last):
  File "clone.py, line 16 in <module>
    reader.write(text)
  File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 60 in write
    id, text_in = self.write_no_block(text)
  File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 78, in write_no_block
    data.extended(bytearray(text.ljust(len(self.BLOCK_ADDRS) * 16).encode('ascii')))
UnicodeEncodeError: 'ascii' codec cant encode characters in position 1-2: ordinal not in range(128)

What can I do to fix this?