skip to Main Content

How to remove json elements and reformat it

I have the follow JSON as an output of an enumerate function. {'question': (0, 'Who invented the light bulb?'), 'answers': [{'answer': 'Thomas Edison', 'score': '2.0'}, {'answer': 'Nikola Tesla', 'score': '2.0'}, {'answer': 'Albert Einstein', 'score': '0.0'}], 'error': "We didn't quite get…

VIEW QUESTION

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue?

I have the following code for a server listening on a port: def handle_oracle_query(self, sock, address): sockIn = sock.makefile('rb') sockOut = sock.makefile('wb') line = sockIn.readline() submitted_data = json.loads(line) self.get_thread_specific_storage()['environmental_variables'] = submitted_data['environmental_variables'] self.get_thread_specific_storage()['cgi'] = submitted_data['cgi'] generate_output() print_output(sockOut) sock.close() sockIn.close() sockOut.close() self.remove_thread_specific_storage()…

VIEW QUESTION
Back To Top
Search