UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 1409: illegal multibyte sequence
时间: 2023-10-22 11:29:26 浏览: 105
当你使用pyquery库读取本地HTML文件时,报错"UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 1409: illegal multibyte sequence",这是由于编码问题导致的。根据引用中的代码,你正在使用GBK编码来读取文件,但是文件中包含了无法解码的多字节序列。为了解决这个问题,你可以在打开文件时指定编码为UTF-8,例如:file = open(f, "r", encoding="utf-8")。这样就能够正确地读取文件并避免编码错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [pyquery报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte](https://download.csdn.net/download/weixin_38665944/13751270)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [解决UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaf in position 14: illegal multibyte ...](https://blog.csdn.net/m0_59856692/article/details/130932880)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [已解决UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaf in position 27: illegal multibyte ...](https://blog.csdn.net/weixin_53817810/article/details/131050449)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文