码迷,mamicode.com
首页 > 编程语言 > 详细

关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法

时间:2016-09-10 19:09:11      阅读:1569      评论:0      收藏:0      [点我收藏+]

标签:

#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"错误,解决办法

标签:

原文地址:http://www.cnblogs.com/lyhc/p/5859976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!