title: Compress data in Java and decompress in Python
body: <p>So I am trying to compress (gzip or similar format) a JSON object before I throw it in my MySQL database.  I am currently storing the data as BLOB.  I have tried to use the following Java method to compress the data:</p>
  
  <pre><code>public static byte[] compress(String str) throws Exception {
      if (str == null || str.length() == 0) {
          return null;
      }
  
      ByteArrayOutputStream obj = new ByteArrayOutputStream();
      GZIPOutputStream gzip = new GZIPOutputStream(obj);
      gzip.write(str.getBytes("UTF-8"));
      gzip.close();
      return obj.toByteArray();
  }
  </code></pre>
  
  <p>and then store it in the database using <code>setBytes()</code> with a <code>PreparedStatement</code> and am having no issues with this.  What I am having issues with is decrypting the data in Python 2.7  I have tried using <code>zlib.decompress()</code> to no avail.  It can't seem to read the data that Java is storing.  I also need to write a conversion script in Python to compress the old rows into this new format.  So whatever format I needs to be readable by the Python <code>decompress()</code> whether it was compressed with Java or Python 2.7</p>
  
  <p>I am happy to provide anymore information that can assist in helping to find a solution to my dilemma.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: Some of the Python Code:</p>
  
  <pre><code>class KitPvPMatch(Base):
      """ The SQLAlchemy declarative model class for a User object. """
      __tablename__ = 'kit_pvp_matches'
      __table_args__ = {
          'mysql_engine': 'InnoDB',
          'mysql_charset': 'utf8'
      }
  
      match_id = Column(INTEGER(11), autoincrement=True, primary_key=True, nullable=False)
      season = Column(Unicode(5), nullable=False)
      winner = Column(Unicode(16), nullable=False)
      loser = Column(Unicode(16), nullable=False)
      ladder_id = Column(TINYINT(4), nullable=False)
      data = Column(BLOB, nullable=False)
  
  # The line in question
  jsonData = json.loads(zlib.decompress(match.data))
  
  # The error
  error: Error -3 while decompressing data: incorrect header check
  </code></pre>