Skip to content

Commit e8a7597

Browse files
authored
Merge pull request #19 from FoamyGuy/master
If data is dictionary send it as form data
2 parents 9d75832 + 7385253 commit e8a7597

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

adafruit_requests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
212212
data = json_module.dumps(json)
213213
sock.send(b"Content-Type: application/json\r\n")
214214
if data:
215+
if isinstance(data, dict):
216+
sock.send(b"Content-Type: application/x-www-form-urlencoded\r\n")
217+
_post_data = ""
218+
for k in data:
219+
_post_data = "{}&{}={}".format(_post_data, k, data[k])
220+
data = _post_data[1:]
215221
sock.send(b"Content-Length: %d\r\n" % len(data))
216222
sock.send(b"\r\n")
217223
if data:

0 commit comments

Comments
 (0)