encryption - Python code returning error 'Object is not callable' -
so, have started playing around encryption coding , have been trying create unique encryption key based time. code far :
from threading import timer pyclbr import function import hashlib, binascii, time key1="" buffer1="" buffer2="" class repeatedtimer(object): def __init__(self, interval, function, *args, **kwargs): self.timer=none self.function=function self.interval=interval self.args=args self.kwargs=kwargs self.is_running=false self.start() def _run(self): self.is_running=false self.start() self.function(*self.args,**self.kwargs) def start(self): if not self.is_running: self.timer=timer(self.interval,self._run) self.timer.start() self.is_running=true def stop(self): self.timer.cancel() self.is_running=false def generatekeys(): global key1 global buffer1 global buffer2 t=int((time.time())/10) t=hashlib.sha1(str(t).encode('utf-8')) t=t.hexdigest() t=t.encode('utf-8') t=binascii.hexlify(t) t=t.decode('utf-8') t=t[0:11] t=int(t)>>5 buffer2=buffer1 buffer1=key1 key1=str(t) def printkeys(): print("keys : "+key1+" "+buffer1+" "+buffer2) timerstart=repeatedtimer(10,generatekeys()) #generatekeys(); timerstart2=repeatedtimer(11,printkeys())
whenever run above code keep getting error:
exception in thread thread-49: traceback (most recent call last): file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 923, in _bootstrap_inner self.run() file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 1189, in run self.function(*self.args, **self.kwargs) file "/users/kiro/documents/liclipse workspace/encryptionfinal/pkg/enc_keygen.py", line 22, in _run self.function(*self.args,**self.kwargs) typeerror: 'str' object not callable exception in thread thread-50: traceback (most recent call last): file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 923, in _bootstrap_inner self.run() file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 1189, in run self.function(*self.args, **self.kwargs) file "/users/kiro/documents/liclipse workspace/encryptionfinal/pkg/enc_keygen.py", line 22, in _run self.function(*self.args,**self.kwargs) typeerror: 'nonetype' object not callable
does have idea why? want generatekeys() function keep running every 10 seconds , printkeys() function tell me keys every 11 seconds (to check assigning keys correctly global variables).
this more experimentation in fixing code working.
with line
timerstart=repeatedtimer(10,generatekeys())
you handing on result of call generatekeys()
__init__
method. want do, hand on function itself. must not call it:
timerstart = repeatedtimer(10, generatekeys)
Comments
Post a Comment