简体   繁体   English

fnv 0.2.0用法TypeError

[英]fnv 0.2.0 Usage TypeError

I am trying to use fnv hash function on python-3.6, but I am getting an error 我正在尝试在python-3.6上使用fnv哈希函数,但出现错误

Traceback (most recent call last): File "C:/Users/SACHIN/AppData/Local/Programs/Python/Python36/bloom.py", line 4, in module fnv.hash(data, algorithm=fnv.fnv_1a, bits=64) File "C:\\Users\\SACHIN\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\fnv__init__.py", line 52, in hash OFFSET_BASIS[bits] File "C:\\Users\\SACHIN\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\fnv__init__.py", line 28, in fnv_1a return ensure_bits_count((hash_value ^ byte) * PRIMES[bits], bits) TypeError: unsupported operand type(s) for ^: 'int' and 'str' 追溯(最近一次通话最近):文件“ C:/Users/SACHIN/AppData/Local/Programs/Python/Python36/bloom.py”,模块fnv.hash(数据,算法= fnv.fnv_1a,位)中的第4行= 64)文件“ C:\\ Users \\ SACHIN \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ site-packages \\ fnv__init __。py”,第52行,哈希值OFFSET_BASIS [bits]文件“ C:\\ Users \\ SACHIN \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ site-packages \\ fnv__init __。py“,第28行,位于fnv_1a中,返回sure_bits_count((hash_value ^ byte)* PRIMES [bits],bits)TypeError:不支持的操作数类型)for ^:'int'和'str'

For code 对于代码

import fnv

data = 'my data'
fnv.hash(data, algorithm=fnv.fnv_1a, bits=64)
fnv.hash(data, bits=64)
fnv.hash(data, algorithm=fnv.fnv, bits=64)

which is exactly copied from https://pypi.python.org/pypi/fnv/0.2.0 完全从https://pypi.python.org/pypi/fnv/0.2.0复制

Please let me know what actually is wrong. 请让我知道实际上有什么问题。

Just ran into this error today. 今天刚遇到这个错误。 I got around it by encoding the string. 我通过编码字符串来解决它。 For example, the below should all work. 例如,下面的所有方法都可以。

import fnv

data = 'my data'
fnv.hash(data.encode(), algorithm=fnv.fnv_1a, bits=64)
fnv.hash(data.encode('ascii'), bits=64)
fnv.hash(data.encode('utf-8'), algorithm=fnv.fnv, bits=64)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM