I have a simple web server written in Python3 (using classes from http.server ) which I am transferring from 2 to 3.
I have the following code:
What throws away:
TypeError: keys must be a string
Checking the data, I decided that parse_qs apparently encodes the keys as bytes, which throws an error ( json apparently doesn't like bytes).
import json json.dumps({b'Throws error' : [b"Keys must be a string"]}) json.dumps({'Also throws error': [b'TypeError, is not JSON serializable']}) json.dumps({'This works': ['No bytes!']})
What is the best solution here? With Python 2, the code works fine because parse_qs uses str instead of bytes . My initial thought is that I probably need to write a JSON serializer. Not that it was difficult for something so simple, but I would prefer not to do it if I can do it the other way (for example, translate the dictionary to use strings instead of bytes).
source share