Python爬虫'utf-8' codec can't decode byte 0xxx in position 1: invalid start byte的解决方案

Python抓取数据时,如果header添加了

accept_encoding = 'gzip, deflate, br'

无论如何转码都会出现 'utf-8' codec can't decode byte 0xxx in position 1: invalid start byte 的错误

只需将 accept_encoding = '' 设置为空即可

原因:

本地接收压缩格式的数据,服务器传过来压缩格式gzip的文件,而解压这种gzip文件只能用deflate算法,浏览器能够自动解压,程序却不能自动解压gzip,需要额外进行设置才行。

posted @ 2023-02-15 22:30  乱炖er  阅读(534)  评论(0编辑  收藏  举报