Python响应解码

Python响应解码,python,utf-8,decode,urllib,html-encode,Python,Utf 8,Decode,Urllib,Html Encode,对于以下使用urllib的行: # some request object exists response = urllib.request.urlopen(request) html = response.read().decode("utf8") read()返回什么格式的字符串?我一直在试图从Python的文档中弄明白这一点,但它根本没有提到这一点。为什么会有解码?decode是否将对象解码为utf-8或从utf-8?从什么格式到什么格式解码解码文档也没有提到这一点。是Python的文档

对于以下使用
urllib
的行:

# some request object exists
response = urllib.request.urlopen(request)
html = response.read().decode("utf8")
read()
返回什么格式的字符串?我一直在试图从Python的文档中弄明白这一点,但它根本没有提到这一点。为什么会有
解码
decode
是否将对象解码为utf-8或utf-8?从什么格式到什么格式解码<代码>解码文档也没有提到这一点。是Python的文档太糟糕了,还是我不了解一些标准惯例

我想将HTML存储在UTF-8文件中。我会只是做一个常规的写作,还是我需要“编码”回一些东西并写下来

注意:我知道urllib已被弃用,但我现在无法切换到urllib2

>>> r=urllib.urlopen("http://google.com")
>>> a=r.read()
>>> type(a)
0: <type 'str'>
>>> help(a.decode)
Help on built-in function decode:

decode(...)
    S.decode([encoding[,errors]]) -> object

    Decodes S using the codec registered for encoding. encoding defaults
    to the default encoding. errors may be given to set a different error
    handling scheme. Default is 'strict' meaning that encoding errors raise
    a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
    as well as any other name registered with codecs.register_error that is
    able to handle UnicodeDecodeErrors.

>>> b = a.decode('utf8')
>>> type(b)
1: <type 'unicode'>
>>> 
>>r=urllib.urlopen(“http://google.com")
>>>a=r.read()
>>>类型(a)
0: 
>>>帮助(a.解码)
关于内置函数解码的帮助:
解码(…)
S.decode([encoding[,errors]])->object
使用注册用于编码的编解码器进行解码。编码默认值
设置为默认编码。可能会给出错误以设置不同的错误
处理方案。默认值为“strict”,表示编码错误会引发
独角兽。其他可能的值为“忽略”和“替换”
以及在codecs.register\u中注册的任何其他名称
能够处理UnideDecodeErrors。
>>>b=a.decode('utf8')
>>>类型(b)
1: 
>>> 

因此,
read()
似乎返回一个
str
.decode()
从UTF-8解码为Python的内部unicode格式。

感谢没有评论的否决票…?太棒了,谢谢@root!出于某种原因,我所在的
decode()
doc页面是另一个页面。Thankso a
str
不支持所有unicode字符,因此
decode()
read()
之后链接?