Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send a dictionary with python http server/client

I am using the libraries http.server and http.client in order to build a server/client structure. The server is always on and the client makes requests.

When the server is called, it calls a scraper that returns a dictionary and currently I send it like this:

self.wfile.write(str(dictionary).encode("utf-8"))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However the client receives a String that I have to parse. Is it possible that the server could send a dictionary? (Or even better, a json)

>Solution :

You should try to use json.dumps({"a": 1, "b": 2}) and send your JSON object instead of encoding it as utf-8.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading