Skip to content

Commit 095eba4

Browse files
committed
when sending data get the bytes length not the string length
1 parent a7fe259 commit 095eba4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

adafruit_requests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,12 @@ def _send_request(
609609
for k in data:
610610
_post_data = "{}&{}={}".format(_post_data, k, data[k])
611611
data = _post_data[1:]
612+
if isinstance(data, str):
613+
data = bytes(data, "utf-8")
612614
self._send(socket, b"Content-Length: %d\r\n" % len(data))
613615
self._send(socket, b"\r\n")
614616
if data:
615-
if isinstance(data, bytearray):
616-
self._send(socket, bytes(data))
617-
else:
618-
self._send(socket, bytes(data, "utf-8"))
617+
self._send(socket, bytes(data))
619618

620619
# pylint: disable=too-many-branches, too-many-statements, unused-argument, too-many-arguments, too-many-locals
621620
def request(

0 commit comments

Comments
 (0)