2016-03-06 68 views
0

我在python3中看不到urllib.request模块。引发以下错误。我错过了什么吗?我想访问urllib.request.urlopen我在python3中看不到urllib.request模块。引发错误

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 19 2015, 20:38:52) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import urllib 
>>> urllib.request 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
AttributeError: 'module' object has no attribute 'request' 
>>> 

根据以下链接urllib应该有请求模块。 https://docs.python.org/3.4/library/urllib.request.html#urllib.request.Request.method

回答

0

在Python 3,你需要导入urllib.request而不是urllib

像这样:

>>> import urllib.request 
>>> urllib.request.Request 
<class 'urllib.request.Request'>