类型错误: 'int' 不支持缓冲区接口



我想在将变量转换为整数后为其赋值。我的代码:

timStamp = int(time.time()) // 30

但是我收到以下错误:

TypeError: 'int' does not support the buffer interface

我也试过:

timStamp = time.time() // 30

这次我得到了:

TypeError: 'float' does not support the buffer interface

我已经在谷歌上搜索过,但没有找到我要找的答案。N:B:我正在使用python 3,我的完整源代码如下http://paste.ubuntu.com/10584501/

您应该查看完整的回溯,以了解错误发生的位置。在这种情况下,代码产生,

/tmp/test2.py in get_totp(secret)
     41     #timStamp = int (time.time() // 60)
     42     timStamp = int(time.time()) // 60
---> 43     return get_hotp(secret, base64.b16encode(timStamp))
TypeError: 'int' does not support the buffer interface

所以问题是base64.b16encode需要一个字节字符串,而是被赋予了一个 int 或一个浮点数。

但是,我可以理解这种混乱,因为此异常比您提供的行晚一行。

最新更新