python http请求时gzip解压

#!/usr/bin/env python  
# encoding=utf-8  
  
import urllib2, httplib  
import StringIO, gzip 

#解压gzip
def gzdecode(data) :
    compressedstream = StringIO.StringIO(data)
    gziper = gzip.GzipFile(fileobj=compressedstream)  
    data2 = gziper.read()   # 读取解压缩后数据 
    return data2 

你可能感兴趣的:(python http请求时gzip解压)