关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法
Posted 远方的风lyh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法相关的知识,希望对你有一定的参考价值。
#encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.urlopen(url).read() data = data.decode(\'UTF-8\') print(data)
报错:import urllib.request ImportError: No module named request
解决办法;
#encoding:UTF-8 import urllib url = "http://www.baidu.com" data = urllib.urlopen(url).read() data = data.decode(\'UTF-8\') print(data)
原因查询源码 (python3.5.2) ,urllib moudle中并没有request相关方法,直接是urlopen方法
from urlparse import urljoin as basejoin __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve", "urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus", "urlencode", "url2pathname", "pathname2url", "splittag", "localhost", "thishost", "ftperrors", "basejoin", "unwrap", "splittype", "splithost", "splituser", "splitpasswd", "splitport", "splitnport", "splitquery", "splitattr", "splitvalue", "getproxies"]
以上是关于关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法的主要内容,如果未能解决你的问题,请参考以下文章