urllib.request.urlopen(url).read().decode(‘utf-8‘)
url中带中文参数会出错:UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 84-86: ordinal not in range(128)
需要对中文进行转码
url = GEOCODE_BASE_URL + urllib.parse.quote(‘北京市‘)
文档中对urlib.parse.quote的描述:The URL quoting functions focus on taking program data and making it safe for use as URL components by quoting special characters and appropriately encoding non-ASCII text.
原文:http://www.cnblogs.com/colleen/p/4604799.html