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

 阳光而灿烂61 发布于 2022-11-02 13:30

源码:

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吗?

1 个回答
  • 这样就好了

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

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

    2022-11-04 18:06 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有