# -*- coding: utf-8 -*-
# Python3
import urllib
import urllib.request as url_req
opener = url_req.build_opener()
url='http://zh.wikipedia.org/wiki/'+"毛泽东"
opener.open(url).read()
# opener.open(url.encode("utf-8")).read()
# # doesn't work either
当我运行它时,它抱怨说:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-12: ordinal not in range(128)
但我不能使用.encode()
任何一个,因为它会抱怨:
Traceback (most recent call last):
File "t.py", line 8, in <module>
opener.open(url.encode("utf-8")).read()
File "/usr/local/Cellar/python3/3.2.2/lib/python3.2/urllib/request.py", line 360, in open
req.timeout = timeout
AttributeError: 'bytes' object has no attribute 'timeout'
任何人都知道如何处理?