Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error in python3 when producer message key/value is not encoded as bytes #1327

Closed
adityaguptacmu opened this issue Dec 19, 2017 · 3 comments
Assignees

Comments

@adityaguptacmu
Copy link

Python 3 will not automatically cast objects.

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 374, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 629, in protected_call
return self.run(*args, **kwargs)
File "/code/KafkaProducer/xyz.py", line 35, in xyz
record_metadata = future.get(timeout=10)
File "/usr/local/lib/python3.6/site-packages/kafka/producer/future.py", line 63, in get
raise self.exception # pylint: disable-msg=raising-bad-type
File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 513, in send
key_bytes, value_bytes)
File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 655, in _partition
available)
File "/usr/local/lib/python3.6/site-packages/kafka/partitioner/default.py", line 29, in call
idx = murmur2(key)
File "/usr/local/lib/python3.6/site-packages/kafka/partitioner/hashed.py", line 82, in murmur2
((data[i4 + 2] & 0xff) << 16) +
TypeError: unsupported operand type(s) for &: 'str' and 'int'

@dpkp
Copy link
Owner

dpkp commented Dec 26, 2017

The underlying issue here is that you are trying to send data that has not been encoded to bytes. We could definitely make the error handling better here. In the meantime, please verify that your code is sending bytes not strings (or that you are using key and/or value encoders).

@dpkp dpkp changed the title python-3.6.2 + kafka-python==1.3.5 Confusing error when attempting to send non-bytes with python3 Dec 26, 2017
@dpkp dpkp changed the title Confusing error when attempting to send non-bytes with python3 Confusing error in python3 when producer message key/value is not encoded as bytes Dec 26, 2017
@adityaguptacmu
Copy link
Author

Sorry for getting back late. The data is of type:

<class 'bytes'>

@WesleyBatista
Copy link

had the same issue here and just noticed that I wasn't setting the 'key_serializer' in the KafkaProducer instantiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants