Python 如何处理server返回gzip压缩过的内容,代码如下:

from StringIO import StringIOimport gzip

request = urllib2.Request('http://outofmemory.cn/')
request.add_header('Accept-encoding', 'gzip')
response = urllib2.urlopen(request)if response.info().get('Content-Encoding') == 'gzip':
    buf = StringIO( response.read())
    f = gzip.GzipFile(fileobj=buf)
    data = f.read()

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
猜你喜欢
  • 2021-12-05
  • 2022-01-04
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
相关资源
相似解决方案