title: Python3 GZip Compressing String
body: <p>I am trying to do the following with Python3:</p>
  
  <pre><code>data = json.dumps(packet)
  s = StringIO()
  g = gzip.GzipFile(fileobj=s, mode='w')
  g.write(data)
  g.close()
  gzipped_body = s.getvalue()
  </code></pre>
  
  <p>But it keeps complaining with the following error:</p>
  
  <pre><code>TypeError: string argument expected, got 'bytes'
  </code></pre>
  
  <p>The example code I'm using is based on Python2 so I am thinking there is some changes in StringIO that might be causing this but I'm not sure. Anyone give me some hints on how to get a gzipped string of some JSON in Python3?</p>