urllib,urllib2,urllib.request.open,AttributeError:“模块”对象没有属性“ urlopen”

garg10may

我正在尝试使用,urllib但显示错误,版本是Python 2,我也尝试使用urllib2urllib.request.open()

import urllib
import sys

print (sys.version)

myurl = urllib.urlopen('http://www.profmcmillan.com')
print (myurl)

输出:

2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
..
AttributeError: 'module' object has no attribute 'urlopen'

与urllib2

import urllib2
import sys

print (sys.version)

myurl = urllib2.urlopen('http://www.profmcmillan.com')
print (myurl)

输出:

2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
..
    myurl = urllib2.urlopen('http://www.profmcmillan.com')
AttributeError: 'module' object has no attribute 'urlopen'

同样,如果我导入urllib并使用urllib.request.open

肠杆菌

可能是你命名你的文件urllib.py,或者你有你的Python路径这样的文件。因此:

import urllib

它不会导入真正的urllib库,而是您的文件之一。您可以使用以下方法检查模块文件路径:

import urllib
print urllib.__file__

例如我的是指: /usr/lib/python2.7/urllib.pyc

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

AttributeError:模块“ urllib”没有属性“ urlopen”

Python urllib.request.urlopen:AttributeError:“ bytes”对象没有属性“ data”

带有验证的urllib.request.urlopen(url)

urllib2 : AttributeError 'strip',

AttributeError:模块'urllib.request'没有属性'user'

模块“ urllib”没有属性“ request”

AttributeError:模块“ urllib3”在python中没有属性“ urlopen”

urllib.request => AttributeError: 'set' 对象没有属性 'items'

如何使用 urllib.request.urlopen 从多个 url 获取所有图像 url

python:urllib2如何使用urlopen请求发送cookie

转换urllib2 python代码以使用urllib模块

urllib,urllib2,urllib3和请求模块之间有什么区别?

Urllib2和JSON对象错误

HTTP错误401:未经授权使用urllib.request.urlopen

HTTPError问题:urllib.request.urlopen python请求错误

将 urllib.request.urlopen 移动到请求

python:urllib.request.urlopen不起作用

如何处理来自urllib.request.urlopen()的响应编码

模拟urllib.request.urlopen的read函数返回MagicMock签名

替换urllib.request.urlopen(url,ca *)的开启器

Python 3:urllib.request.urlopen和Progressbar

urllib.request 的 urlopen 无法在 python 3.7 中打开页面

urllib.request.urlopen 不适用于特定网站

我需要使用urllib2.Request / urlopen处理哪些错误/异常?

为什么有时urllib.request.urlopen不起作用,但浏览器起作用?

导入错误:没有模块名称urllib2

避免使用urllib,urllib2和request等语法的“厄运金字塔”

urllib.request和urllib2都不起作用

urlopen('http .....')。read()中的read()有什么作用?[urllib]