【问题标题】:I don't see urllib.request module in python3. Throws error我在 python3 中没有看到 urllib.request 模块。抛出错误
【发布时间】:2016-06-19 18:02:01
【问题描述】:

我在 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。

【问题讨论】:

    标签: python-3.4 urllib


    【解决方案1】:

    在 Python 3 中,您需要导入 urllib.request 而不是 urllib'

    像这样:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 2022-01-03
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多