首页  >  问答  >  正文

python - 使用requests获取网页源码的时候报错:failed to decode gzip

源码:

import requests
if __name__ == "__main__":
    url = "http://www.wnlwedu.com/"
    r = requests.get(url=url)
    print r.text

报错信息:

requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing: incorrect data check',))

requests不是会自动解压gzip吗?

PHPzPHPz2741 天前2277

全部回复(1)我来回复

  • 怪我咯

    怪我咯2017-04-17 14:24:56

    这样就好了

    pythonrequests.get(url=url, headers={'Accept-Encoding': ''})
    

    可能是因为这网站没用gzip压缩吧

    回复
    0
  • 取消回复