I have the following line which receives a string upon incoming web request.
data_from_flask = c.recv(2048).decode('utf8')
The message is
'GET / HTTP/1.1\r\nHost: localhost:31477\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nsec-ch-ua: "Microsoft Edge";v="105", " Not;A Brand";v="99", "Chromium";v="105"\r\nsec-ch-ua-mobile: ?0\r\nsec-ch-ua-platform: "Windows"\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\nSec-Fetch-Site: cross-site\r\nSec-Fetch-Mode: navigate\r\nSec-Fetch-User: ?1\r\nSec-Fetch-Dest: document\r\nAccept-Encoding: gzip, deflate, br\r\nAccept-Language: en-US,en;q=0.9\r\n\r\n'
I want to load this to a JSON format using
job_json = json.loads(data_from_flask)
If I directly run this, I get the following error
The exception has occurred: JSONDecodeError
Expecting value: line 1 column 1 (char 0)
because the incomming string is not entirely in JSON format.
What is the simplest way I could do this? Is there any special encoding I could use ?