diff options
author | Dana Powers <dana.powers@rd.io> | 2014-08-31 10:04:17 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2014-09-04 12:14:45 -0700 |
commit | 3ec3989ca1ef14cf0b84ecf4e5e5f9c5e0eb00aa (patch) | |
tree | a9b236d207a8cb36895cb2bdc916cb896602bd8c | |
parent | 8cfc4c01d8b276402a289a56cc2e26f5fa419f0b (diff) | |
download | kafka-python-3ec3989ca1ef14cf0b84ecf4e5e5f9c5e0eb00aa.tar.gz |
Change message type requirement from str to bytes for clarity and prep for python3
-rw-r--r-- | kafka/producer.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/kafka/producer.py b/kafka/producer.py index 8a6bff0..b28a424 100644 --- a/kafka/producer.py +++ b/kafka/producer.py @@ -156,11 +156,11 @@ class Producer(object): Helper method to send produce requests @param: topic, name of topic for produce request -- type str @param: partition, partition number for produce request -- type int - @param: *msg, one or more message payloads -- type str + @param: *msg, one or more message payloads -- type bytes @returns: ResponseRequest returned by server raises on error - Note that msg type *must* be encoded to str by user. + Note that msg type *must* be encoded to bytes by user. Passing unicode message will not work, for example you should encode before calling send_messages via something like `unicode_message.encode('utf-8')` @@ -172,9 +172,9 @@ class Producer(object): if not isinstance(msg, (list, tuple)): raise TypeError("msg is not a list or tuple!") - # Raise TypeError if any message is not encoded as a str - if any(not isinstance(m, str) for m in msg): - raise TypeError("all produce message payloads must be type str") + # Raise TypeError if any message is not encoded as bytes + if any(not isinstance(m, bytes) for m in msg): + raise TypeError("all produce message payloads must be type bytes") if self.async: for m in msg: |