AttributeError: 'module' 对象没有属性 'request'

问题描述:

当我在 Python 3.3 中运行以下代码时:

When I run the following code in Python 3.3:

import urllib
tempfile = urllib.request.urlopen("http://yahoo.com")

我收到以下错误:

我也这样做是为了验证:

I did this too to verify:

我做错了什么?

urllib 模块已被拆分为多个部分,并在 Python 3 中重命名为 urllib.requesturllib.parseurllib.error.

The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.

导入 urllib.request 而不是 urllib.

import urllib.request