Skip to content

Commit

Permalink
Merge pull request #112 from Neradoc/fix-send-content-length
Browse files Browse the repository at this point in the history
When sending data get the bytes length not the string length
  • Loading branch information
dhalbert authored Aug 3, 2022
2 parents a7fe259 + 095eba4 commit 6b72737
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,12 @@ def _send_request(
for k in data:
_post_data = "{}&{}={}".format(_post_data, k, data[k])
data = _post_data[1:]
if isinstance(data, str):
data = bytes(data, "utf-8")
self._send(socket, b"Content-Length: %d\r\n" % len(data))
self._send(socket, b"\r\n")
if data:
if isinstance(data, bytearray):
self._send(socket, bytes(data))
else:
self._send(socket, bytes(data, "utf-8"))
self._send(socket, bytes(data))

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

0 comments on commit 6b72737

Please sign in to comment.