I have a response object of byte type into convert to JSON and get data from it.
response = b'{"message": "test msg 3"}'
My code :
try:
response = response.decode('utf-8')
LOGGER.info(response)
data = json.load(response)
message = data["message"]
except AttributeError as err:
message = "Message not delivered..."
LOGGER.warning(err)
When response.decode('utf-8') executes it become {"message": "test msg 3"}
But Each time i am getting a error while executing json.load(response):
'str' object has no attribute 'read'
Can anyone point me why this happening ?
Solution :
Use json.loads() instead of json.load() . Because json.load() loads a file and json.loads() loads a String.