AttributeError:“module”对象没有“request”属性

2024-05-23 13:37:38 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我得到以下错误:

enter image description here

我这么做也是为了证实:

enter image description here

我做错什么了?


Tags: 代码importcomhttprequest错误urllibtempfile
3条回答

有趣的是,我注意到一些依赖IDE的行为。

Spyder和PyCharm在我的机器上都使用同一个解释器:在PyCharm中我需要这样做

import urllib.request

在斯皮德的时候

import urllib

做得很好

导入urllib.request,而不是urllib

import urllib.request

如果这是在PyCharm上,就像我的一样,请确保您的文件名不是urllib.py。

相关问题 更多 >