我在python3中没有看到urllib.request模块。引发以下错误。我错过了什么吗?我想访问urllib.request.urlopen
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 :(得分:3)
在Python 3中,您需要导入urllib.request
而不是urllib
&#39;
像这样:
>>> import urllib.request
>>> urllib.request.Request
<class 'urllib.request.Request'>