Raspberry Pi Asked by RLahey on October 5, 2021
I’ve set up a RC522 Card on my pi using This Tutorial 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?
Ah, your hotel card might contain non ASCII characters, say Unicoded Chinese. So you need to decode the Unicoded Chinese characters each of which is denoted by two bytes. Of course hotel cards usually use other tricks to punish the bad guys trying to clone.
Answered by tlfong01 on October 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP