Skip to content

Commit 3ec3989

Browse files
author
Dana Powers
committed
Change message type requirement from str to bytes for clarity and prep for python3
1 parent 8cfc4c0 commit 3ec3989

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kafka/producer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ def send_messages(self, topic, partition, *msg):
156156
Helper method to send produce requests
157157
@param: topic, name of topic for produce request -- type str
158158
@param: partition, partition number for produce request -- type int
159-
@param: *msg, one or more message payloads -- type str
159+
@param: *msg, one or more message payloads -- type bytes
160160
@returns: ResponseRequest returned by server
161161
raises on error
162162
163-
Note that msg type *must* be encoded to str by user.
163+
Note that msg type *must* be encoded to bytes by user.
164164
Passing unicode message will not work, for example
165165
you should encode before calling send_messages via
166166
something like `unicode_message.encode('utf-8')`
@@ -172,9 +172,9 @@ def send_messages(self, topic, partition, *msg):
172172
if not isinstance(msg, (list, tuple)):
173173
raise TypeError("msg is not a list or tuple!")
174174

175-
# Raise TypeError if any message is not encoded as a str
176-
if any(not isinstance(m, str) for m in msg):
177-
raise TypeError("all produce message payloads must be type str")
175+
# Raise TypeError if any message is not encoded as bytes
176+
if any(not isinstance(m, bytes) for m in msg):
177+
raise TypeError("all produce message payloads must be type bytes")
178178

179179
if self.async:
180180
for m in msg:

0 commit comments

Comments
 (0)