2016-03-06 67 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'>