Zklib in ERPNext

i am new to zklib and ERPNext. I am developing a finger authentication attendance app in ERPNext using zklib for ZKTeco device. I have created app and successful done every thing, i have installed zklib in frappe directory but when i call this funtion it says zk.connect can not be found in zklib.py Here is my code:

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _

import sys
import time
from zklib import zklib, zkconst

class Attendence(self):
     def call_Attendence(self):
          print("Function called")
          zk = zklib.ZKLib("", 4370)
          ret = zk.connect()
          print("connection:", ret)

Shouldn’t zk be defined before using the connect function ?
Something like zk = zklib.ZKLib(machine_ip, int(port)) where machine_ip would be localhost address and port would be 8000, I guess.

thanks i forgot to add the line here,
zk = zklib.ZKLib(“”, 4370)
i have already done this but it gives error

I can use the code outside frappe, and it work fine but inside frappe app it give errors about importing

1 Like

You need to add zklib in your app’s requirements.txt


zk=zklib.ZKLib("", 8000) ? What port is 4370 ?

Its working at 4370 out side frappe-bench app. if i run the code independently out side the frappe, it execute without any issue.

@hereabdulla i did and restart the frappe-bench but its not working :frowning:

I never tried zklib but I am using pyzk it is working inside Frappe will you try that

1 Like

You need to run bench setup requirements if you are changing something in the requirements.txt


This solution is also Not working…! :frowning:

@hereabdulla i am facing same error at import, as used zklib…
from base import ZK
ImportError: No module named ‘base’

Which zk device model are you using.we used zkilb to connect iface450 model zkteco device

zk = zklib.ZKLib(“”, 4370)
ret = zk.connect()

this always gives as false.

do we need to do any setting on device.

please give the steps to connect to the device

I tried only with pyzk only lets try with zklib and let you know

1 Like

@renjukumar for connection, check the IP and port of device, you have to set the port manually.

@Sibghat y dont u try pyzk

@hereabdulla, @Zlash65 do i need to include every import within zklib, i tried zklib and pyzk and both give error inside their own libraries. may i share screen shots ?

While using pyzk library:
my Code:

       from zk import ZK, const
 def call_Attendence():
 conn = None
 zk = ZK('', port=4370, timeout=5)
    conn = zk.connect()
        users = conn.get_users()
    for user in users:
        privilege = 'User'
        if user.privilege == const.USER_ADMIN:
            privilege = 'Admin'
        print('  Name       : {}'.format(user.name))
except Exception:
    print("Process terminate :")
    if conn:

And i get this Error:
i Use this command to run my function: frappe-bench$ bench execute “pathto function”: Response i get is here:
Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.5/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/sibghat/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module> main() File "/home/sibghat/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main click.Group(commands=commands)(prog_name='bench') File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/home/sibghat/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func ret = f(frappe._dict(ctx.obj), *args, **kwargs) File "/home/sibghat/frappe-bench/apps/frappe/frappe/commands/utils.py", line 120, in execute ret = frappe.get_attr(method)(*args, **kwargs) File "/home/sibghat/frappe-bench/apps/frappe/frappe/__init__.py", line 919, in get_attr return getattr(get_module(modulename), methodname) File "/home/sibghat/frappe-bench/apps/frappe/frappe/__init__.py", line 704, in get_module return importlib.import_module(modulename) File "/home/sibghat/frappe-bench/env/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 665, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/home/sibghat/frappe-bench/apps/attendence2/attendence2/doctype/attendence/attendence.py", line 8, in <module> from zk import ZK, const File "/home/sibghat/frappe-bench/env/lib/python3.5/site-packages/zk/__init__.py", line 2, in <module> from base import ZK ImportError: No module named 'base'

Hi, can you clarify where does the data land inside ERPNext? Will it work if I want to use the ZK check-in check-out information to calculate salary based on hours worked? Tried with zklib without success. Thanks.

Hi, were you able to fix this? Also are you looking for integration of one device or multiple devices across many locations like outlets in different areas of the city/country etc.