title: Python3 json.dumps gives TypeError: keys must be a string
body: <p>I've got a simple web server written in Python3 (using classes from <code>http.server</code>) that I'm porting from 2 to 3.</p>
  
  <p>I have the following code:</p>
  
  <pre><code># More code here...
  postvars = cgi.parse_qs(self.rfile.read(length),
                          keep_blank_values=1)
  something.json_run(json.dumps(postvars))
  </code></pre>
  
  <p>Which throws:</p>
  
  <pre><code>TypeError: keys must be a string
  </code></pre>
  
  <p>By inspecting the data, I've determined that <code>parse_qs</code> seems to encode the keys as bytes, which is what's throwing the error (<code>json</code> doesn't like bytes, apparently).</p>
  
  <pre><code>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!']})
  </code></pre>
  
  <p>What is the best solution here? With Python 2, the code works fine because <code>parse_qs</code> uses <code>str</code> instead of <code>bytes</code>. My initial thought is that I probably need to write a JSON serializer. Not that it's difficult for something so simple, but I'd prefer not to if I can do it some other way (e.g. translate the dictionary to using strings instead of bytes).</p>