Skip to content

Commit 56d7643

Browse files
authored
Merge pull request #8 from brentru/sock-send
Switch to Socket.Send
2 parents 59a467e + 338a50d commit 56d7643

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

adafruit_requests.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,30 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
192192
else:
193193
conntype = _the_interface.TCP_MODE
194194
sock.connect(addr_info[-1], conntype)
195-
sock.write(b"%s /%s HTTP/1.0\r\n" % (method, path))
195+
sock.send(b"%s /%s HTTP/1.0\r\n" % (method, path))
196196
if "Host" not in headers:
197-
sock.write(b"Host: %s\r\n" % host)
197+
sock.send(b"Host: %s\r\n" % host)
198198
if "User-Agent" not in headers:
199-
sock.write(b"User-Agent: Adafruit CircuitPython\r\n")
199+
sock.send(b"User-Agent: Adafruit CircuitPython\r\n")
200200
# Iterate over keys to avoid tuple alloc
201201
for k in headers:
202-
sock.write(k.encode())
203-
sock.write(b": ")
204-
sock.write(headers[k].encode())
205-
sock.write(b"\r\n")
202+
sock.send(k.encode())
203+
sock.send(b": ")
204+
sock.send(headers[k].encode())
205+
sock.send(b"\r\n")
206206
if json is not None:
207207
assert data is None
208208
try:
209209
import json as json_module
210210
except ImportError:
211211
import ujson as json_module
212212
data = json_module.dumps(json)
213-
sock.write(b"Content-Type: application/json\r\n")
213+
sock.send(b"Content-Type: application/json\r\n")
214214
if data:
215-
sock.write(b"Content-Length: %d\r\n" % len(data))
216-
sock.write(b"\r\n")
215+
sock.send(b"Content-Length: %d\r\n" % len(data))
216+
sock.send(b"\r\n")
217217
if data:
218-
sock.write(bytes(data, "utf-8"))
218+
sock.send(bytes(data, "utf-8"))
219219

220220
line = sock.readline()
221221
# print(line)

0 commit comments

Comments
 (0)