Skip to content

Commit

Permalink
Merge pull request #19 from FoamyGuy/master
Browse files Browse the repository at this point in the history
If data is dictionary send it as form data
  • Loading branch information
tannewt committed Feb 24, 2020
2 parents 9d75832 + 7385253 commit e8a7597
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
data = json_module.dumps(json)
sock.send(b"Content-Type: application/json\r\n")
if data:
if isinstance(data, dict):
sock.send(b"Content-Type: application/x-www-form-urlencoded\r\n")
_post_data = ""
for k in data:
_post_data = "{}&{}={}".format(_post_data, k, data[k])
data = _post_data[1:]
sock.send(b"Content-Length: %d\r\n" % len(data))
sock.send(b"\r\n")
if data:
Expand Down

0 comments on commit e8a7597

Please sign in to comment.