Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python代码返回错误';对象不可调用';_Python_Encryption - Fatal编程技术网

Python代码返回错误';对象不可调用';

Python代码返回错误';对象不可调用';,python,encryption,Python,Encryption,所以,我开始玩加密编码,并一直试图创建一个唯一的加密密钥的基础上从时间。这是我目前的代码: from threading import Timer from pyclbr import Function import hashlib, binascii, time key1="" buffer1="" buffer2="" class RepeatedTimer(object): def __init__(self, interval, function, *args, **kwar

所以,我开始玩加密编码,并一直试图创建一个唯一的加密密钥的基础上从时间。这是我目前的代码:

from threading import Timer
from 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())
无论何时运行上述代码,我都会不断收到错误:

线程thread-49中的异常: 回溯(最近一次呼叫最后一次): 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py”,第923行,在bootstrap\u内部 self.run() 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py”,第1189行,正在运行 self.function(*self.args,**self.kwargs) 文件“/Users/Kiro/Documents/LiClipse Workspace/EncryptionFinal/pkg/enc_keygen.py”,第22行,正在运行 self.function(*self.args,**self.kwargs) TypeError:“str”对象不可调用 线程-50中的异常: 回溯(最近一次呼叫最后一次): 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py”,第923行,在bootstrap\u内部 self.run() 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py”,第1189行,正在运行 self.function(*self.args,**self.kwargs) 文件“/Users/Kiro/Documents/LiClipse Workspace/EncryptionFinal/pkg/enc_keygen.py”,第22行,正在运行 self.function(*self.args,**self.kwargs) TypeError:“非类型”对象不可调用 有人知道为什么吗?我想要的是generateKeys()函数每10秒运行一次,printKeys()函数每11秒告诉我这些键(检查是否将键正确分配给全局变量)

这比任何事情都更具实验性,但我希望能帮助修复此代码,因为我希望它能够正常工作。

与您的产品线一起使用

timerStart=RepeatedTimer(10,generateKeys())
您正在将调用
generateKeys()
的结果移交给
\uuu init\uu
方法。实际上,您想要做的是移交函数本身。那么你不能称之为:

timerStart = RepeatedTimer(10, generateKeys)