Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions adafruit_esp32spi/adafruit_esp32spi_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def text(self):

def json(self):
"""The HTTP content, parsed into a json dictionary"""
import ujson
return ujson.loads(self.content)
try:
import json as json_module
except ImportError:
import ujson as json_module
return json_module.loads(self.content)

def iter_content(self, chunk_size=1, decode_unicode=False):
"""An iterator that will stream data by only reading 'chunk_size'
Expand Down Expand Up @@ -176,8 +179,11 @@ def request(method, url, data=None, json=None, headers=None, stream=False):
sock.write(b"\r\n")
if json is not None:
assert data is None
import ujson
data = ujson.dumps(json)
try:
import json as json_module
except ImportError:
import ujson as json_module
data = json_module.dumps(json)
sock.write(b"Content-Type: application/json\r\n")
if data:
sock.write(b"Content-Length: %d\r\n" % len(data))
Expand Down