我有点好奇为什么我的代码导致了这个错误? 有人能告诉我一些洞察力作为解决这个问题的方法以及它提高它的原因吗?
错误:
chunk += " " (16 - len(chunk) % 16)
TypeError: 'str' object is not callable
我的代码:
def upload(item):
with open(item, "rb") as fp:
while True:
chunk = fp.read(64*1024)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += " " (16 - len(chunk) % 16)
self.s.send(encrypt(self.key, chunk, self.iv))
self.s.send("DONE")
self.update()
将chunk += " " (16 - len(chunk) % 16)
更改为:
chunk += " " * (16 - len(chunk) % 16)
如果你什么都没有,那就意味着" "
是可调用的,你试图用16 - len(chunk) % 16
参数调用它。