一些'utf-8'编解码器不能解码字节 [英] Some 'utf-8' codec can't decode byte
本文介绍了一些'utf-8'编解码器不能解码字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 wget
代码下载网站时出现错误:
code:
import threading
import urllib.request
import os
import re
import time
import json
def wget(url):
#self.url = url
data = os.popen('wget -qO- %s'% url).read()
return data
print (wget("http://jamesholm.se/dj.php"))
错误:
Traceback (most recent call last):
File "stand-alone-check-url.py", line 13, in <module>
print (wget("http://jamesholm.se/dj.php"))
File "stand-alone-check-url.py", line 10, in wget
data = os.popen('wget -qO- %s'% url).read()
File "/usr/local/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9a in position 13133: invalid start byte
如何克服这个错误?
推荐答案
而不是wget,使用请求
python模块。
Instead of wget, use requests
python module.
>>> import requests
>>> data = requests.get("http://jamesholm.se/dj.php").text
>>> print(data)
这篇关于一些'utf-8'编解码器不能解码字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文