title: How to iterate through and unzip ".gz" files in python?
body: <p>I have several sub-folders, each of which containing twitter files which are zipped. I want python to iterate through these sub-folders and turn them into regular JSON files.
  I have more than 300 sub-folders, each of which containing about 1000 or more of these zipped files. 
  A sample of these files is named:
       00_activities.json.gz%3FAWSAccessKeyId=AKIAJADH5KHBJMUZOPEA&amp;Expires=1404665927&amp;Signature=%2BdCn%252Ffn%2BFfRQhknWWcH%2BtnwlSfk%3D"</p>
  
  <p>Thanks in advance</p>
  
  <p>I have tried the codes below, just to see if I can extract one of those files, but none worked. </p>
  
  <pre><code>import zipfile
  zip_ref = zipfile.ZipFile('E:/echoverse/Subdivided Tweets/Subdivided Tweets/Tweets-0', 'r')
  zip_ref.extractall('E:/echoverse/Subdivided Tweets/Subdivided Tweets/Tweets-0/00_activities.json.gz%3FAWSAccessKeyId=AKIAJADH5KHBJMUZOPEA&amp;Expires=1404665927&amp;Signature=%2BdCn%252Ffn%2BFfRQhknWWcH%2BtnwlSfk%3D')
  zip_ref.close()
  </code></pre>
  
  <h1>I have also tried:</h1>
  
  <pre><code>import tarfile
  tar = tarfile.open('E:/echoverse/Subdivided Tweets/Subdivided Tweets/Tweets-0/00_activities.json.gz%3FAWSAccessKeyId=AKIAJADH5KHBJMUZOPEA&amp;Expires=1404665927&amp;Signature=%2BdCn%252Ffn%2BFfRQhknWWcH%2BtnwlSfk%3D')
  tar.extractall()
  tar.close
  </code></pre>
  
  <h1>here is my third try (and no luck):</h1>
  
  <pre><code>import gzip
  import json
  with gzip.open('E:/echoverse/Subdivided Tweets/Subdivided Tweets/Tweets-0/00_activities.json.gz%3FAWSAccessKeyId=AKIAJADH5KHBJMUZOPEA&amp;Expires=1404665927&amp;Signature=%2BdCn%252Ffn%2BFfRQhknWWcH%2BtnwlSfk%3D'
  , 'rb') as f:
      d = json.loads(f.read().decode("utf-8"))
  </code></pre>
  
  <p>There is another very similar threat on stackover flow, but my question is different in that my zipped file is originally JSON, and when I use this last method I get this error:
      Exception has occurred: json.decoder.JSONDecodeError
  Expecting value: line 1 column 1 (char 0)</p>