2

I am trying to use fnv hash function on python-3.6, but I am getting an error

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'

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

Please let me know what actually is wrong.

sachin rathod
  • 541
  • 1
  • 9
  • 23

1 Answers1

2

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)
Matt BS
  • 35
  • 8