fananimi / pyzk

Unofficial library of zkteco fingerprint attendance machine
GNU General Public License v2.0
489 stars 319 forks source link

Adding a User with Persian Name in pyzk #190

Open Haghghii opened 1 year ago

Haghghii commented 1 year ago

I am encountering difficulties when attempting to add a user with a Persian name in pyzk, a Python library for ZKTeco devices. Despite my efforts, the device does not accept Persian characters as valid input for user names. I have followed the provided documentation and attempted to use the set_user function with the Persian name as the name parameter, but it does not work as expected.

I would appreciate assistance in finding a solution or alternative approach that allows me to add a user with a Persian name successfully in pyzk.

kurenai-ryu commented 1 year ago

Ok, you need to post some example code, with example data. just to note that the zk constructor has a encoding parameter, that defaults to 'UTF-8' Which is used inside some methods with this approach:

name_pad = name.encode(self.encoding, errors='ignore').ljust(24, b'\x00')[:24]

maybe the ignore errors makes the string empty or incomplete, in that case you need to provide a correct encoding.

core-burner commented 2 weeks ago

Encoding is indeed UTF-8 but according to

name_pad = name.encode(self.encoding, errors='ignore').ljust(24, b'\x00')[:24]

with persian characters(2-3 bytes in UTF-8) the name length is limited 8 to 12 letters. It's not a good place to store names. This should depend on device. If there is an error, res needs to be provided.